6 ms·
The issue I see with a Rust GUI framework that has a target to be native on multiple platforms is that certain platforms (iOS, macOS) have their toolkits so tig
by saagarjha 7y ago
The issue I see with a Rust GUI framework that has a target to be native on multiple platforms is that certain platforms (iOS, macOS) have their toolkits so tightly bound to a certain language (Objective-C for Cocoa, Swift for SwiftUI) that it just doesn’t seem feasible to call into it without making using horrible, hacky, unidiomatic Rust code. I’ve seen projects that aim to support macOS literally having code like NSArray(msgSend!(objc::Class(“NSArray”).unwrap(), new)) and it’s just so awful :(
- Razengan 7y agoThe state of cross-platform GUI systems really is a bizarre mess in this day and age, and probably can only be solved with a concentrated joint effort by Apple, Google and Microsoft. Personally I'd love to have something like import SwiftUI // For controls that are common to all OSes import SwiftUI.Windows // For OS specific features
- skohan 7y ago> probably can only be solved with a concentrated joint effort by Apple, Google and Microsoft. It's hard to imagine that happening. None of these companies have an interest in making it easier to port code away from their platform.
- Razengan 7y agoMaybe one day when they are populated by employees who grew up with dismay over the state of xplat GUI. :) I mean even now Apple has an increased focus on services that must be accessible from everywhere: Music, TV, iCloud Drive. Surely there must be someone there who wishes they had to write most code only once for all OSes without making their app a hog. I'd settle for just a convention; i.e. let C# remain the primary language on Windows, but introduce SwiftUI-like primitives like Text, HStack, ForEach etc.
- pjmlp 7y agoBasically XAML/WPF/UWP code first.
- Razengan 7y agoWhich one is their latest tech? Where does "WinUI" fit in? Is there a good, single starting point like SwiftUI's tutorial? The first hit brought me to "Host a custom UWP control in a WPF app using XAML Islands" so there seems to be a distinction (and it implies WPF isn't the star anymore?) [0] [1] that I could find after a couple searches look way more complex than what the equivalent SwiftUI would be. <Button x:Name="button" Content="Hello, world!" HorizontalAlignment="Left" Margin = "152,293,0,0" VerticalAlignment="Top"/> vs. Button(action: play) { Text("Hello, world!") // Don't need alignment etc. to produce identical output. } and ugh [2]: > If you need to embed any Unicode characters into the text, you can use the standard XML syntax. For example, to put the greeting in smart quotes, use: <Label Text="“Hello, XAML!”" /> I suggested emulating SwiftUI's syntax because it seems to be the most succinct. [0] https://github.com/microsoft/Windows-appsample-photo-lab/blob/master/PhotoLab/MainPage.xaml https://github.com/microsoft/Windows-appsample-photo-lab/blo... [1] https://docs.microsoft.com/en-us/windows/uwp/get-started/create-a-hello-world-app-xaml-universal https://docs.microsoft.com/en-us/windows/uwp/get-started/cre... [2] https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/get-started-with-xaml https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/...
- pjmlp 7y agoYou are looking at XAML, which underlines WPF, Silverlight, UWP/WinUI as the layout description language. You can also do it in pure .NET code without XML, hence why I specifically mentioned code first. So to pick on your example, var btn = new Button { Name = "Button", Content = "Hello, world!", HorizontalAlignment = HorizontalAlignment.Left, }; btn.Click += (s, e) => { // handle click event }; Slightly more verbose, but one can still wrap those calls, or just pick Fabulous, https://github.com/fsprojects/Fabulous https://github.com/fsprojects/Fabulous WinUI is the latest tech, just UWP as usual, still the future of Windows UI, now re-architected not to depend on a specific Windows 10 release, going back all the way to Falls Creator.
- setr 7y agoHowever, they do have an interest in making it easier to port code to their platform.
- deleted 7y ago[deleted]
- raphlinus 7y agoUsing the widget set provided by the platform is not easy, and that's not what druid tries to do. Rather, there's a platform abstraction layer (druid-shell) that takes care of all this stuff for you, and has all that nasty unsafe code in it, then it draws its own widgets. We try to feel more "native" in that we're using platform menus and so on. It's certainly possible to be more native (calling into Cocoa widgets) or less (using Web technology), but I think what we're doing is a good pragmatic approach. Of course, things have gotten a bit postmodern, even on macOS there is no single widget toolkit, but basically a series of choices of what technology to build on. I'm actually not sure that binding other languages to SwiftUI is going to work well at all, but in Objective-C it works fine, just isn't very smooth. On Windows, I've generally found COM to be quite pleasant, and noises coming from Microsoft suggest that story will become even better.
- saagarjha 7y ago> it draws its own widgets I have never seen this go well in practice :( Qt and Flutter do this and the experience is just…not great. Do you have any ideas on how to do better than them if you're using this approach?
- raphlinus 7y agoTo be clear, we're focusing on the use case of a font editor, where you're mostly interacting with highly custom views, much less so with layouts composed of stock widgets. As I said elsewhere, increasingly we're in a world where there isn't a standard set of platform UI widgets. I think that was the case when we had Cocoa on macOS, but on Windows it's a choice between MFC, WinForms, WPF, WinUI, and those are only some of the choices offered by Microsoft itself. It's a good question, though. It's possible somebody will figure out a good way to abstract over officially supported platform UI toolkits, and if so, that might become a compelling choice. This is one reason why the main point of my blog is that we need to figure out the best approach, rather than just assuming we know what to build.
- Macha 7y agoMFC and WinForms both just abstractions over Win32. WPF was clearly targeting being indistinguishable from the old widgets and had a much better success rate than other reimplementation attempts. It's really only with UWP/WinUI that you'd notice the difference without going searching and that has received a lot of consequent complaints.
- nitwit005 7y agoThat problem is normally solved by creating a nicer API abstraction around it. Windows and OS-X tend to be the more straightforward cases. There is a standard set of UI components which users expect. Things are murkier in the Unix world, with multiple libraries and display technologies.
- raphlinus 7y agoI'm genuinely curious. Is there a good example of a cross-platform wrapper around platform widgets? That was the original design brief of AWT, which turned out quite bad. Is there a successor which actually gets it right?
- nitwit005 7y agoI obviously haven't tried every library, but my experience has been they all have some problems. You have to expect things like differing text wrapping and scroll behavior because it's hard to completely abstract the underlying UI frameworks. The alternative of custom painting everything tends to come with more difficult to fix issues however. AWT's successor Swing struggled with things like respecting system user preferences and accessibility. You can find some old Java 1.5 write ups about it: https://web.mit.edu/java_v1.5.0_22/distrib/share/docs/guide/swing/1.4/windows.html https://web.mit.edu/java_v1.5.0_22/distrib/share/docs/guide/...
- pnako 7y agowxWidgets is the most popular one. It's an ambitious project that allows accessing true native widgets, not just from C++ but also from other languages like Python, etc.
- twic 7y agoSomeone had a go at a Rust binding of wxWidgets five years ago: https://github.com/kenz-gelsoft/wxRust https://github.com/kenz-gelsoft/wxRust As they mention, this is based on a C wrapper round wxWidgets' native C++ API, originally developed to aid in developing a Haskell binding to wxWidgets: http://wxc.sourceforge.net/ http://wxc.sourceforge.net/ The Rust binding is probably bitrotted for modern Rust, but since it's mostly generated, generating a low-level API using bindgen, which is actively maintained, and then a high-level API using a Python script of its own, it might be fairly easy to resurrect. bindgen has got pretty good at converting C++ APIs, so it might be worth trying it on wxWidgets' native API, too. I have no plans to write a GUI application in Rust myself, but i would love for there to be a good option for other people to write native GUI apps in Rust. As many other commenters have noted, cross-platform synthetic GUIs never look or behave quite right.