it seems ridiculous that we have to embed an entire browser, meant for internet web browsing, just to create a cross-platform UI with moderate ease.

Why are native or semi-native UI frameworks lagging so far behind? am I wrong in thinking this? are there easier, declarative frameworks for creating semi-native UIs on desktop that don’t look like windows 1998?

52 points
*

Ha! I’m partially looking at this issue in my bachelor’s thesis.

It’s not at all necessary to embed a browser, but it’s really easy to transfer your web app to a “near native” experience with stuff like electron, ionic, cordova, react native or whatever other web stuff is out there. The issue is mostly that native APIs are complicated and relying on web views or just providing your own “browser” is a relatively easy approach.

Stuff like Flutter, Xamarin or .NET MAUI compile depending on the platform to native or are interpreted by a runtime. There’s a study I use that compares Flutter to React Native, native Java and Ionic on Android and finds that unsurprisingly the native implementation is best, but is closely followed by Flutter (with a few hiccups), with the remainder being significantly slower.

The thing is. I don’t think these compiled frameworks lag behind in any way. But when you have a dev team, that’s competent in web development, you won’t make them learn C#, Xaml, Dart or C++, just to get native API access - you’ll just let a framework handle that for you because it’s cheaper and easier.

Edit: To add some further reading. This paper and this one explore the different approaches out there and suggest which one might be “the best”. I don’t feel like they’re good papers, but there’s almost no other write up of cross-platform dev approaches out there.

Edit2: I also believe that the approach “we are web devs that want access to native APIs” may be turned around in the future, since Flutter and now also .NET offer ways to deploy cross-platforn apps as web apps. I’ll get back to writing the thesis now and stop editing.

permalink
report
reply
4 points

You may also want to checkout xilem

permalink
report
parent
reply
4 points

I remember thinking that Qt seemed like a really good approach that should be more widely adopted…until I actually had to use it.

Not that it’s terrible; it’s really not. But C++ is just not at all a good language for <s>anything</s> UI stuff.

permalink
report
parent
reply
4 points

QML on the other hand is awesome imo.

permalink
report
parent
reply
39 points
*

It’s not that native UIs are lagging behind, there is a whole set of reasons.

TL;DR: browsers, as opposed to desktop apps, are stardartized - because they were originally designed to display and deliver text documents. We were never supposed to build complex application UIs on a web stack.

First, there is no standard way of making native UI on a desktop. Every OS uses it’s own solution, while Linux offers several different ones. Browsers rely on a set of open standards developed specifically for the web, and even there not everything works exactly the same.

Second, browsers are designed to draw a very specific kind of UI through a very specific rendering mode - they run an immutable hierarchy of elements through layouting and painting engines. It works great for documents, but it becomes extremely unweildy for most other things, which is why we have an entire zoo of different UI implementations (crutches, most of them) for browsers.

On the desktop we often make a choice of what UI technology would fit best our purpose. For a game engine I would use an immediate-mode UI solution like ImGUI, for the ease of prototyping, integration and fast iterations.

For consumer software I might choose between something like QT or GTK for robust functionality, reliable performance, acessibility and community support. Mobile platforms come with their own native UI solutions.

For data-intensive UIs and heavy editors (e.g. CAD, video and music production, games) I might need to designan entirely new rendering pipeline to comply with users requirements for ergonomics, speed, latency etc.

It is also easy to notice that as a team or employer, it is often much easier to hire someone for web stack, than for native development. Simply put, more people can effectively code in JS, so we get more JS and tech like Electron enables that.

If you are interested in a single solution that will get you nice results in general, no matter the platform - you might see some success with projects like Flutter or OrbTK.

UI rendering in general is a deep and very rewarding rabbit hole. If you are in the mood, this article by Raph Levien gives a good overview of existing architectures: https://raphlinus.github.io/rust/gui/2022/05/07/ui-architecture.html

permalink
report
reply
33 points

This is because each desktop operating system using a different graphics rendering engine—Quartz on macOS and X/Wayland on Linux, for example. In order to write an application that works on all major operating systems, you either need to use a graphics library that has already done the heavy lifting of calling the native frameworks under the hood or you have to do it yourself. Or you can use a web-based graphics library that has also already done that heavy lifting, with the added advantage that you can use languages like HTML, CSS, and Javascript to easily create visual elements. This is attractive when the alternatives like Qt are notoriously difficult to deploy and force you to use C/C++.

permalink
report
reply
7 points
*

Quartz (usually referred to as Core Graphics) isn’t recommended anymore on Macs.

Developers should be using SwiftUI now, which is a completely different approach:

class HelloWorldView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        // Drawing code here.
        guard let context = NSGraphicsContext.current?.cgContext else { return }

        // Set text attributes
        let attributes: [NSAttributedString.Key: Any] = [
            .font: NSFont.systemFont(ofSize: 24),
            .foregroundColor: NSColor.black
        ]

        // Create the string
        let string = NSAttributedString(string: "Hello World", attributes: attributes)

        // Draw the string
        string.draw(at: CGPoint(x: 20, y: 20))
    }
}

Here’s the same thing with SwiftUI:

struct HelloWorldView: View {
    var body: some View {
        Text("Hello World")
            .font(.system(size: 24))
            .foregroundColor(.black)
            .padding()
    }
}
permalink
report
parent
reply
6 points

Quartz is a layer beneath SwiftUI or AppKit. SwiftUI is still using Quartz under the hood. The way you use Quartz directly from SwiftUI vs AppKit is a bit different, though still fairly similar. A more fair comparison of the SwiftUI code would be:

struct HelloWorldView: View {
  var body: some View {
    Canvas { context, _ in
      context.draw(
        Text("HelloWorld")
          .font(.system(size: 24))
          .foregroundColor(.black),
        at: CGPoint(x: 20, y: 20)
      )
    }
  }
}

Alternatively an AppKit solution (not using Quartz directly) would be something like:

class HelloWorldView: NSView {
  override init(frame frameRect: NSRect) {
    super.init(frame: frameRect)
    let text = NSAttributedString(
      string: “Hello World”,
      attributes: [.font: NSFont.systemFont(ofSize: 24), .foregroundColor: NSColor.black]
    )
    let label = NSTextField(labelWithAttributedString: text)
    addSubview(label)
  }

  required init?(coder: NSCoder) {
    fatalError()
  }
}

In either AppKit or SwiftUI, you can access Quartz directly to implement custom views. However, most of the time the UI code you write in either SwiftUI or AppKit won’t call Quartz directly at all, but will instead be composed of built-in views, like (NS)TextField or (NS)Button. Under the hood, SwiftUI is mainly just using the AppKit components at the moment, but provides a significantly nicer way to use them (especially in regards to layout and data synchronization).

permalink
report
parent
reply
23 points
2 points

I’m not too familiar with slinr or fybe but DearImGui seems like an odd one out here.

permalink
report
parent
reply
21 points

You mean like qt/qml? Due mind that even with those ui toolkits you will need to ship ‘some’ library. In case of QT it is not minimal at all. GTK can be more minimal but it still is significant.

Also there is tauri. Which doesn’t ship a browser, but uses the platform native we view and is compiled while still having an amazing dev experience.

permalink
report
reply
4 points

How is webview different from a browser exactly?

permalink
report
parent
reply
5 points

Electron apps ship their own chromium-based renderer, but ‘webview’ means the OS gets to use its own renderer. It’s still a browser-like environment, but at least the OS can choose the most performant one.

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 3.5K

    Monthly active users

  • 1.6K

    Posts

  • 26K

    Comments