Microsoft-ui-xaml: Proposal: WinUI 3 rust support

Created on 20 May 2020  路  14Comments  路  Source: microsoft/microsoft-ui-xaml

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.

feature proposal

Most helpful comment

winrt-rs is maybe able to achieve the connection, but an explicit winui3-rs crate that pulls in the necessary dependencies and has a working hello world will make it much much more accessible.

All 14 comments

Language mappings seem to be already worked on: https://github.com/microsoft/winrt-rs

winrt-rs is maybe able to achieve the connection, but an explicit winui3-rs crate that pulls in the necessary dependencies and has a working hello world will make it much much more accessible.

This is (likely) blocked by winrt-rs being stable.

@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.
Rust is increasingly more popular for a reason. It's a really good language, and Microsoft has even said to be using rust for building some part of Windows.
Having an app framework built around rust would mean c++ level performance but with much better readable code and less memory bugs.

@kennykerr "I'd love to hear what else folks are looking for."
the main motivation was to be able to have professional-looking applications that are written as much natively in rust as possible. Somehow it seems that people that have great language design skills are not the same ones that have great artistic UI widget design skills. So a wrapper in rust for WIN UI 3 would bridge the divide. But the barrier to entry is high when there are libraries that should do the trick but have no example of actually doing so. Having a hello world example that ties the technologies together will get a lot more people to actually want to dive in and make their own derivations of it. I personally would love an example of rust using WIN UI 3 and DirectX12 in a panel within the WIN UI app. I did not start working on it since it seemed hard when also only just starting to learn rust.

I've been looking forward to doing more GUI work in Rust. WinUI sounds like just the place to try it out

@kennykerr "Having a hello world example that ties the technologies together will get a lot more people to actually want to dive in and make their own derivations of it."

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.
https://bodil.lol/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?
Edit: It would be great if there was a roadmap for supporting rust with winui

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.

Was this page helpful?
0 / 5 - 0 ratings