-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: WinUI 3 rust support #2488
Comments
Language mappings seem to be already worked on: https://github.com/microsoft/winrt-rs |
|
This is (likely) blocked by |
@kennykerr as FYI |
The Rust winrt crate provides the language projection and packaging support, comparable to C++/WinRT with its VS extension and NuGet support. All of that is provided by Rust/WinRT today. It's on my list to add some Xaml samples soon. We still have some way to go to support building your own Xaml controls in Rust, but you can already build basic Xaml apps and we are working furiously to get complete type system support in place. I'd love to hear what else folks are looking for. I can imagine this is more about providing support for the kinds of things that the Xaml compiler traditionally takes care of, but I may be wrong. |
I would really love to see this happen too. |
@kennykerr "I'd love to hear what else folks are looking for." |
I've been looking forward to doing more GUI work in Rust. WinUI sounds like just the place to try it out |
Hello world is enough to show the ui. An example todo app shows some simple interactions, and how the pieces fit together. I remember the announcement about .Net MAUI, and I'm wondering how much of the underpinnings of that are in WinUI? |
To me, the inspiration comes from a Rust GUI framework called vgtk. This framework's syntax is heavily inspired by React's jsx syntax for building declarative UI, and it's programming model is the nowadays popular MVU model. To declare an app, you write fn view(&self) -> VNode<Model> {
gtk! {
<Application::new_unwrap(None, ApplicationFlags::empty())>
<Window border_width=20 on destroy=|_| Message::Exit>
<HeaderBar title="inc!" show_close_button=true />
<Box spacing=10 halign=Align::Center>
<Label label=self.counter.to_string() />
<Button label="inc!" image="add" always_show_image=true
on clicked=|_| Message::Inc />
</Box>
</Window>
</Application>
}
} This is very close to jsx, but even more close to XAML which is perfect to use for WinUI. This syntax in rust is enabled by rust's procedural macros feature. It seems to me that this type of UI framework is the trend these days, and for rust with WinUI to succeed, it needs to ride this train as well. This type of work has been done countless times, and it's probably very easy for Microsoft to create one for WinUI. It might also be a good chance for a cross platform UI framework as that's what the rust GUI community eagerly await, but that seems to be out of scope of this issue. |
Something also of note is that, XAML requires 'partial class' support, right? So you can add controls to the UI elements. Does Rust support this? Could you imitate it with procedural macros? |
Thanks for all the feedback! Keep it coming. @suleyth - the Xaml API doesn't require partial classes. That's a feature of the C# language that the Xaml compiler makes use of. For C++ and now Rust we're exploring a completely different approach that is more natural to those languages. And yes, procedural macros are a great way to solve this in Rust. We use them extensively in winrt-rs. |
Any update on this? |
I can't speak for the WinUI team, but much of the support for Rust will come from the Rust/WinRT language projection (winrt-rs). In particular, I'm now working on adding support for defining and implementing COM and WinRT types in Rust. That's a major prerequisite for complete Xaml integration. Once that's ready, we can start looking at lighting up Xaml binding support more naturally in Rust. |
Can you please post example code for a basic xaml app ? |
@kennykerr I'd love to see how creating a WinUI app is right now. It might be clunky, but I'd still love to see how far I can take it so long as the way to do it is at least somewhat documented. Example code would be wonderful to have. |
I expect furious work is needed first before Rust/WinRT versions of HelloXaml and Blocks ... samples can be posted alongside Ocr sample. |
Xaml still requires more work to enable, but the Windows crate for Rust (formerly Rust/WinRT) already supports building DirectX and Windows.UI.Composition apps. Here's a Direct2D example: And a Windows.UI.Composition example: More info here: https://github.com/microsoft/windows-rs |
Is this something currently being worked on ?
How far can one go with Composition apps in terms of accepting keyboard text input / list view display? |
Translation in time of the cppwinrt samples like Ocr (done) and HelloXaml, Blocks etc. allows instructive one to one comparisons for those new to Rust. |
Yes, having comparable samples is certainly helpful and I hope to fill in the gaps as support improves for more APIs. Note that you can already write the Blocks sample in Rust. I just haven't got around to that.
It's on my list, but I have been focused on Win32 APIs for the last few months. I hope to look at this again soon.
You can go as far as you want, but it will be harder than simply adding a Xaml TextBox control. 😉 |
That'll work, but I use a screen reader and so Windows.UI.Composition isn't accessible. Is it possible to use the standard win32 controls but with WinRT and without the hastle of XAML? |
The Win32/WinRT Desktop Bridge might help, |
Things are starting to work. 😉 microsoft/windows-rs#81 (comment) |
IMHO this marks the start of a new era for Windows desktop application development. @kennykerr Microsoft is fortunate to have you. Thank you! |
There are now CoreApp and XamlApp examples in the Windows repo. This is based on in-box Xaml within a packaged app, but it should also work for WinUI and desktop apps (I just don't have any such examples yet). Lots more work for me to do, but this is a pretty big step forward for folks interested in experimenting with Rust and UI on Windows. |
@kennykerr I read elsewhere that winui is supposed to also be cross platform via the uno platform. Could rust take advantage of that so I could say build an application for both windows and android? |
Sorry, I have no idea what that would entail. There have been some other requests for cross-platform support in the Windows crate, but at this point I'm squarely focused on completing Windows support. |
@1Dragoon Uno platform is C# only (it doesn't have WinRT APIs, it mimics the WinRT API surface in C#), so no. |
Has anybody at MS ever explored the idea of a Rust macro that could deserialize XAML directly into structs? |
Well, seems like the idea of Rust support for WinUI3 died before it got even usable. At least C# has great Rust interoperability... |
I have succeeded to create WinUI 3 app with Fluent design. Here is the sample code. |
I cloned your repo and ran |
I have no experience of Rust, so I can't help you. Someone here can help you. |
@IngmarBitter If it stopped at bootstrap api, you may be lack of bootstarp dll. Please |
Somewhat related: The Browser Company is making a library to use WinUI 3 in Swift with declarative-like syntax. It's not open-source yet, however they are planning to use it in production, so it shows Xaml can be "used" outside of C# with a great developer experience (IMO better than C# but I'm still a beginner). Porting the Windows SDK (including WinUI) to Swift took them around 8 months with only 2 people working on it (7:18), and the declarative syntax took them 3-4 days (14:45), so this sort of thing can definitely be done. Swift is similar to Rust in terms of not having GC, being based on LLVM, and producing native binaries instead of intermediate code like C#. Update: here it is (very rough still, I suspect it will be more polished by the time their product actually releases for Windows, which I've heard they plan to by the end of the year) Update 2: They have WinRT projections as well now. And WinUI sample code. If a tiny startup can go from zero to WinUI in Swift in a few months, surely a trillion dollar company can do it in Rust, already having WinRT projections? |
Half the world is similar to Rust on those grounds of course But sounds like interesting work |
Any update on this? |
The WinUI team does not seem interested in Rust support. winrt-rs dropped support for WinUI 3 too due the team frequently doing undocumented changes breaking the crate. I don't expect any movement on this in the foreseeable future. |
Rust is becoming increasingly popular. It already can drive DirectX 12 but only in full screen mode or via UI libraries that look like they are made by engineers for engineers. Having WinUI3 support for rust would allow to build rust apps that look modern and polished and under the hood enjoy all the advantages of rust. That would make engineers and marketing happy, i.e. make this combination viable for commercial apps.
The text was updated successfully, but these errors were encountered: