205 points · by belter · 5y ago · 189 comments
1. Write the GUI natively per platform. This is best from a UX perspective but is expensive and you probably need different developers working on different platforms. Other downside is that really advanced functionality is harder to implement and sometimes the performance of native APIs is poor and hard to improve (Apple has this problem frequently).
2. Use a cross-platform framework like Qt (Electron would also go here). This is the most cost-effective solution, but generally does not feel like a native app, which may or may not be a problem.
3. Use a custom GUI framework.[0] Probably the most expensive option and hard to hire developers for, but can be warranted for complex applications like CAD tools, games, etc.
The problem with Rust GUI libraries is that they can't really target 1 or 3 so they need to target option 2. But the big players there are Qt and Electron. Qt is popular because it works well, is proven, and has a lot of financial backing. If you don't need something super complicated a decent Qt developer can get it working quickly. Electron is popular because there are tons of web developers and they can be productive quickly.
Rust attracts a lot of hobbyists who are talented and have good ideas, but I don't think they have the staying power (or financial ability) to provide something that competes with Qt and Electron. I'm sure it can be done in theory but I don't see it happening in practice anytime soon.
[0]: By custom I mean tailored for the type of application you are making, e.g. what a lot of game devs do for their internal tools.
That really depends on the software though. I develop a media software and my users are adamant that they want the exact same look&feel across the three main desktop platforms (to the point that I had to use freetype everywhere for font rendering - thankfully easy with Qt). Also had the same case for a customer at a previous job - I remember comparing screenshots across macOS and Windows until they matched in a pixel-perfect way.
On the other hand, if you're writing, say, a productivity app, calendar, notes manager, most likely it is better for it to fit to each platform.
Although I personally also prefer to use the same apps across platforms, e.g. my main combo no matter whether I'm on Linux / macOS / Win32 is Zim for note-taking, Strawberry for music, Qt Creator for IDE, Seafile for data exchange, Telegram and ripcord for chat, Krita for image manipulation, Darktable for raw photo processing, Digikam for photo collection management ; DaVinci Resolve for video editing.
With the exception of Zim and Darktable which are GTK, all the others are Qt-based.
Are these end-users, or just the person in charge? I find it hard to believe that the actual users of the software would care about this.
If this is editing audio or video, I can 100% believe that. Anything with complex controls that a user has to learn, or keyboard shortcuts, it really matters to end users.
I worked on a Qt app quite a few years ago and that wasn't a media app but it was a complex GUI. Our end users also wanted the exact experience regardless of platform.
On a related note, if you need a rich UI I totally recommend using Qt on the frontend and the backend. Qt isn't just UI libs. There are a bunch of super useful server-side libraries as well that you can use. We used protobufs and had unbelievable performance on the front end and backend. It was a beauty to behold.
Productivity applications like 3Dmax, Photophop, Eagle, Blender and others can take years to master. Even Excell and Word fall into this category.
The last thing a professional needs is to learn the same software 3 times and keep up to date with 3 diverging implementations
I'm fully capable of writing a native app or using Qt but for a large number of apps my clients won't notice a difference and I can be finished faster with Electron so I use Electron.
I even use to just provide a GUI shell over running command line tools. Sure it's "bloated" by some definition of bloated but I get the job done so much quicker and 99% of the cross platform issues disappear.
It's also popular because a browser engine as a lot features that are otherwise difficult to get (e.g. bandwidth-estimated multiplexed video streaming).
This will also suck for users because things like focus, keyboard shortcuts, accessibility, non-English text rendering, etc will probably not work as expected if at all. It turns out there's a lot that goes into GUI that most of us take for granted.
If all the man-hours required to design, write, and coordinate the creation of a GUI toolkit that's the same level of advanced and mature, are instead employed in overcoming any difficulty in creating the best possible bindings, we would end up with a heck of a good quality bindings for Qt and still probably for 1/10th of the human effort. All IMHO, of course.
You are absolutely right. The effort to be acceptable bindings for Qt would be a tiny fraction of the cost compared to building a whole new Rust native GUI library.
Qt is huge set of libraries with an equally huge API. But there are a lot of shortcuts and smart ways of approaching the problem to get what you want out of Qt for minimum effort.
Bindings like PyQt and even PySide go for the nuclear option of generating bindings for the whole Qt API and trying to match the C++ API in style too. This is an absolutely massive huge task. Also, getting people to contribute to an open source bindings project is hard. Getting people to contribute to a bindings generator is even harder.
NodeGui https://github.com/nodegui/nodegui, Qt bindings for Nodejs, on the other hand takes a very different approach which in one way is low-tech but I think is actually very smart. I'll summerise the differences:
* It focuses on Qt Widgets first. This greatly reduces the amount of work to the parts that people actually need. (BTW, if you just want QML and Rust back-end then Jos van den Oever's work at https://invent.kde.org/sdk/rust-qt-binding-generator has probably got you covered already.)
* Mostly hand written, no generation techniques being used. This makes the bindings code repetitive yes, but also easy to understand, easy to debug, and easy to extend. That greatly lowers the barrier for casual contributors.
* Doesn't try to copy the C++ API 1:1. For example, to extend a widget in C++ you are expected to subclass it directly and override methods etc. NodeGui chooses a more composition approach where method you might override are instead exposed as events. Another example, the Qt API is encrusted with convenience methods and overloads. Most of these can be skipped or implemented purely on the JS side.
* Intercepts most events via `QObject::event()` instead of trying to do this method by method (i.e. in QWidget's collection of event handling methods). Smart move.
* Qt has a lot of tiny value classes which can be replaced in the API by JS native objects holding the same data.
The typical response when talking about bindings to Qt is that there are so many impediments to make a decent bridge between language X and the C++ land. But I think that while correct (I've suffered trying to do it myself), it never compares that effort with what would really take to do it from scratch and get to a comparable level of features or robustness. Not only because of the code itself, but because of the knowledge, the know-hows and know-whys of the field, all the tiny decisions that the original library made and you'll take ages to come up with and make too.
This is not to say that Rust could not benefit from the significant effort which has gone into developing Qt, but a Rust port of Qt might be more workable than bindings to the C++ toolkit.
That's an interesting idea! it might be worth considering it, at least.
I wasn't thinking of a full-blown bindings that cover 100% of the API which is an immense task and, as your sibling comments thinks, was a mistake. A more opinionated stance of what parts of the Qt features are deemed necessary seems more feasible in the short to medium term.
I wasn't advocating for one specific way of doing it, but for the more general sentiment that reinventing the wheel and creating a new toolkit from scratch is definitely the most expensive of all the options, in terms of human effort, time dedicated, and progress achieved. We'd basically be decades later than other OSS options, why not build upon their shoulders instead?
However I think you need to differentiate between GUI for internal tools and customer facing products.
Dear ImGui is pretty damn stellar for internal tools. Nigh unbeatable along certain axes. Rust has a couple of Dear ImGui inspired libraries. I think for tools and editors Rust is getting close to being perfectly viable.
For customer facing GUI I largely agree with your assessment.
The most viable competitor to Electron other than Qt are the Java GUI toolkits. There are several but the two main ones are Swing (old, mature, not gonna win any prettiness awards but it gets the job done well enough in IntelliJ), and JavaFX (pretty darn good but people forget about it).
I've shipped apps using JavaFX before. It was quite a pleasant experience and I'd do it again in a heartbeat.
https://www.youtube.com/watch?v=_ZXLCVibI8c
Themes are something they would like to implement and once they have themes they could do native looking themes like Qt (which are perfectly reasonable, I'm generally very happy as a user with Qt applications across all platforms)
I agree with you there is not yet an audience big enough to justify a Qt written for Rust, but who knows, maybe something will change in the next years.
That said, when I had to do something like this, I used Qt with Rust, just because I couldn't justify the time investment of reimplementing a native looking theme on top of Conrod.
Compared to the alternatives (especially Electron, where you oddly forgot to mention this), the performance from native Apple APIs is often the best you can get.
Have you looked at stuff like TextKit 2 etc.?
https://github.com/AccessKit/accesskit
Edit: I'll be spending next week working on a prototype, so I'm confident that I'll soon have something real to show.
But with the popularization of apps, webapps and Electron everyone is accustomed to custom UIs for every app. Does the Spotify app feel Mac-like? Barely. Does it need to be? Not anymore.
I think that as long as we don't see badly-drawn UIs and "ugly styles" (like Java apps’ gradient buttons) we're good nowadays (given that someone actually designed the UI)
I disagree. The fact that most users don't explicitly care is irrelevant — platform conventions are important. They teach a user how to use a new app without having to poke around. Users can drag and drop from one app to another and it just works.
I certainly see the argument that for many companies, it's simply too expensive to write native apps for every platform. But I don't think we need to pretend that non-native apps aren't worse — they're just economical and generally, even at their best, just _okay_.
Congratulations everyone! We're so shitty at our jobs that we've once again lowered everyone's expectations!
https://github.com/microsoft/microsoft-ui-xaml/issues/2488
As mentioned on the thread, the current samples are at https://github.com/microsoft/windows-rs
I just spent a few hours evaluating WinUI 3 for a new project. There's currently no way to hook into the app exit event. Want to flush your SQLite store before you exit? Tough.
It is all a matter of using either UWP or Win32, regarding which API to use.
Win32 use WM_CLOSE
https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-clo...
UWP use Application.Suspending
https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.app...
I would put my money on WinForms being ported to Linux first...
For my part, I'd argue that, if you care about inclusiveness, you should probably favor either Electron or some other option that builds on the Web stack, or writing a separate native front-end for every platform. The problem with all the cross-platform toolkits is that they have accessibility problems.
Check out Lazarus: http://lazarus-ide.org
It is WAY easier than WinForms. WinForms' VS "integration" feels as if they started with what Delphi 1 could do back in 1995 or so, implemented most of it and then decided that is enough.
Lazarus' GUI tools are way above and beyond anything WinForms can do and the underlying LCL is crossplatform using native widgets wherever possible with backends for Win32, Gtk1/Gtk2/Gtk3 (though Gtk2 might be the best ATM), Qt4/Qt5, Cocoa and a few others (Carbon, fpGUI and some Amiga toolkit).
Here is a video from 3 years ago where i make a simple sliding image puzzle game under Linux using it:
https://www.youtube.com/watch?v=s_01Xhd2EJM
Also here is another video from 6 years ago where i make a 2D tilemap editor in Windows:
https://www.youtube.com/watch?v=_3JgeIUo1X0
And another video from ~10 years ago making a doodle app:
more like 76%:
https://www.statista.com/statistics/218089/global-market-sha...
Can't be bothered to verify the tablet claim but that's probably wrong as well.
I have recently added wgpu backend that for now lived in my fork https://github.com/adamnemecek/femtovg
The backend is Piet, which are platform native crates. And then Druid abstracts over those backends. This lets you write GUI code once and then use native API’s and features.
I've written lots about Druid. I haven't really chimed in much in this thread, as a lot of the discussion is frankly not that relevant to what we're trying to do. We are currently not focused on making a good out-of-the-box developer experience, which is what most people here seem to be looking for. Rather, we're systematically exploring what it takes to make a good next-generation UI toolkit, and building a knowledge community around that. It turns out there's quite a bit to that, much more than building a toy UI toolkit.
As mentioned elsewhere, accessibility. Aside from web technology, Qt is one of the very few cross-platform toolkits that gets this right. I'm happy to see that some other projects, egui in particular, are starting to pay attention.
One of the things that Druid doesn't do well right now is integration with 3D and video content. That will depend on the application (it's not needed for font editing), but is definitely needed for a toolkit to be considered general purpose. The implications go deep, mostly because you have to hook pretty deep into the system compositor to do this well.
I may do a blog post on these infrastructure topics, depending on interest.
* Has minimal dependencies
* Looks and works the same on all platforms
* Performs well and gives me the control I need
My conclusion is basically "there's nothing viable". _If_ you are OK with basically limiting yourself to Linux/BSD, the GTK bindings are good. However, for a text editor you'll likely need a custom text widget (the GTK ones aren't very good), and that's where things (with basically any GUI toolkit) get tricky.
There are a few libraries providing Qt bindings for Rust, but they either focus on QML, are only infrequently maintained (e.g. Ritual), or seem to focus more on exposing Rust to C++; not the other way around.
egui looked really interesting, and the immediate mode GUI pattern is really nice to write. Sadly, it's still in the very early stages, and most notably is lacking support for displaying text with different colors/styles.
The rest isn't really worth mentioning I think, at least when wanting to write a text editor. They basically all suffer from the same issues, such as:
- It not being clear if the library will still exist 2 years from now
- Poor support for Unicode (especially Emoji)
- No support for assistive technologies
- Poor support for flexible text rendering (e.g. multiple colors and styles)
- Little to no documentation
For a while I thought about just using Electron, or maybe Sciter (that would at least need fewer resources). Technology wise I think HTML makes sense, as it's very flexible (e.g. many GUI toolkits struggle the moment you want to mix text and e.g. images in the same widget) and quite easy to work with. Sadly, Electron is a fat pig and the last thing I want to do is write Javascript in my spare time. Sciter is proprietary, and you can't distribute the binaries yourself (from what I understand). That basically means your project is dead on arrival, at least if you intend to open source it.
So for now I shelved my idea. Maybe in a year I'll take another look :)
How is this possible given that the Rust language was created to write the rendering engine of Firefox?
Setting that aside, Servo and Firefox both implement the UI side of things from scratch I think. I think from a browser perspective that makes sense: you're already writing a rendering engine, so you may as well also use it for your browser UI.
Rust was Graydon Hoare's personal project. But I don't think Mozilla funded it for no reason.
You can :) You just have to include a copyright notice unless you purchase an exemption.
Recently pushed out a 0.2.1, and did a mini write up here for anyone interested: https://rymc.io/blog/2021/cacao-rs-macos-ios-rust/
I maintain that someone (or a team) needs to just take winsafe/cacao/gtk-rs, slap a declarative layer on top, and do the bare minimum set of controls with hooks for users to do custom things.
There’s other projects that wrap the varying frameworks so I don’t think macOS is as bad as it used to be, but I foresee it still being confusing due to missing docs on Apples side…
* gtk-rs is fairly good, very completely and functional bindings to a functional library. But GTK is also very GNOME/linux centric, is tricky to learn, and not developed as stable or as fast as you might want. Not to knock on the GTK/gtk-rs teams, they're doing amazing work, and imo the best open source GUI library. They've even made great strides in documentation with the new website and API docs recently. Just not quite good enough yet to be recommended for general purpose use. But if you insist on making your GUI in rust, gtk-rs/gtk4-rs optionally with libadwaita-rs is what I'd recommend.
* druid and iced are both promising, but too incomplete.
* egui and RAUI are nice, but meant for gamedev.
[0] gtk-rs.org/
Until there is a mature library that is able to compete with Electron or Qt then I'm afraid that Rust is not a sensible choice for serious cross-platform GUI development at this time.
Like I said before [0] With these libraries, All you get is a mixture of unmaintained or unstable bindings that may break when the GUI library that it is using changes its API.
No thanks and no deal.
To Downvoters: So you are telling me that you can confidently recommend to any engineering shop to develop a very complex GUI app with either of these unstable libraries faster in Rust than one who uses JS/TS with Electron?
Even though I hate Electron, I can see why it is always chosen. Rust for GUI development? I don't think so, especially if you have a short time to release something complex and used by thousands into production.
There is a reason why we don't have options in this domain, apart from Qt, Gtk (with lot's of caveats) and more recently flutter.
Building a cross platform native UI toolkit is an immense amount of work.
It took Google a long time to turn Flutter into a decent option just for Android and iOS, and the newer desktop integrations are still very rough after years of work.
All for Rust implementations are not at all viable for professional usage, and won't get there without major corporate backing.
That said, the gtk bindings are in a good shape and very usable.
If I'm not wrong and something doesn't change, we'll find ourselves surrounded by electron apps on our desktops.
It's a heck of a lot easier to bind to an existing GUI library than writing the equivalent of GTK from scratch. But all languages have this problem, and most of them don't have Microsoft's ability to generate multiple different and incompatible GUI toolkits to suit the fashion of them time.
That said, I think you're right, and I don't see what makes Rust particularly suitable for UI work. I'd just do the UI part in web tech.
I'm not sure what's the advantage of using unsafe code everywhere in Rust compared to just using C/C++. The syntax?
Note: I know there is a GTK tag, but not everything is GTK
I'm still on the DOM-as-the-main-platform train (since 2001, I believe in the Mozilla vision) so I haven't been tracking the details that carefully.
Have a single language to build UIs, target it to multi plattform.
It really isn't, at least if you want to meet the expectations of the users of each platform you're targeting.
It's easy to say "I want a button that says '[Click Me]'." It's less easy to say what the pixels representing that button look like in a platform-agnostic way. Are the corners rounded? What kind of bevel does it have? What sort of visual indication is there when you mouse over?
And then there's stuff like layout. Does your form have the buttons ordered `[OK] [Cancel]` or `[Cancel] [OK]`? Because there are platforms that do both, and if you get it wrong, your user will mis-click because of muscle memory.
And what do you do when one platform supports a widget natively that you don't? Or when the APIs for a "common" widget diverge wildly? Windows Explorer and MacOS Finder serve the same general purpose, but they aren't identical, either from the user's perspective, or from the API perspective.
Java's Swing probably comes closer to "cross platform GUI" than any other package, but it's far, far from perfect, and it solves a lot of these problems by not trying to mimic the underlying OS. Yes, there are themes that get close, but generally, when you're using a Java desktop program, you know you're using a Java desktop program.
A lot of very smart people have tried to create "a single language to build UIs," and "target it to multi platform." It isn't as trivial as you make it seem.
What surprised me was that Tauri was buried and not mentioned as a viable Electron replacement. I think we will eventually get to the point where native OS UI is a Web UI, with the OS UI running on a special virtual interface for security. I have seen Web-based UIs that are every bit as nuanced, complex, and well-designed as native UIs. Two bits are not quite there yet though. First, performance of Web UI has improved amazingly, but until we do have native support integrated into the OS it's going to be a step behind. Second, as already mentioned, accessibility must be accounted for.
(Sure, you can write UIs via WASM now, but that's equally true for Electron)
You didn't live with the computers' UI from the 90's and 00's, right? It looks so.