1
0
Fork 0

state of rust GUIs

This commit is contained in:
Kaan Barmore-Genç 2022-03-17 01:54:10 -04:00
parent 7c61a6d0de
commit b1a66c15bd
3 changed files with 157 additions and 1 deletions

View file

@ -0,0 +1,83 @@
---
title: State of Rust GUIs
date: 2022-03-17
---
> This post is day 2 of me taking part in the
> [#100DaysToOffload](https://100daystooffload.com/) challenge.
The website [Are we GUI Yet?](https://www.areweguiyet.com/) helpfully lists a
lot of the libraries and frameworks available for making a GUI in Rust. I've
been looking into making a GUI program in Rust, so I've been working my way
through some of these options.
This is not a through review, just my thoughts after a brief look. I'd recommend
looking over the website and deciding for yourself.
## Best candidate: Dioxus
- Website: https://dioxuslabs.com/
Dioxus is probably the option I like the best from a quick look. Declarative
applications similar to React, encapsulated components, first class async
support, and good type checking.
Downsides? Right now it's web only. Desktop applications are just web
applications rendered inside a web view. That's okay for cross platform apps,
but not for what I want to do which is a lightweight native application.
## Better Electron: Tauri
- Website: https://github.com/tauri-apps/tauri
Tauri is a really good replacement for Electron. You can see the comparison on
their Github page, smaller binaries, less memory use, and faster launch times.
But again, it is a web app running in a web view. Not a native desktop app. Even
though Tauri uses less memory than electron, it still uses ~180 MB according to
their comparison. And the fast launch time is still around 0.4 seconds, way
longer than what I would expect.
## My current preference: Slint
- Website: https://slint-ui.com/
I really like Slint. It is a native GUI with their own OpenGL renderer, and an
optional Qt backend. From some basic experimentation, it seems to launch in less
than 50ms, and uses less than 80 MB of memory (mostly shared libraries).
You can write the code in either `.slint` files (and they actually have okay
editor support for this file type), or inside macros in your code files. The
code also looks pretty intuitive.
The downsides? The theming support is not great/nonexistent, you can't
dynamically generate UI elements (well kinda, you can generate them based on
properties you change at runtime, but the components themselves are hardcoded),
and the code sometimes gets awkward due to current limitations.
```rust
MainWindow := Window {
// You then have to bind to this callback inside rust code. No way to just write a hook that calls a rust function.
callback save_to_file(string);
HorizontalLayout {
height: 32px;
FilePath := LineEdit {
placeholder_text: "placeholder here";
}
Button {
text: "Save to file";
clicked => { save_to_file(FilePath.text); }
}
}
}
```
There is also no way to do some things, like setting a dialog hint for your main
window, which is something I needed to do.
## Conclusion?
It looks like the state of GUIs in rust is still "not yet". There are a few more
projects I need to look at, like [Relm](https://github.com/antoyo/relm), but
their code looks way too verbose to me. In the end, I think the best option
might be to just write my GUI in C++ with Qt, and maybe integrate bits written
in rust inside of that.

View file

@ -4,7 +4,7 @@ title: A little type system trick in Rust
## date: 2022-03-15 ## date: 2022-03-15
> This post day 1 of me taking a part in the #100DaysToOffload[a] challenge. > This post is day 1 of me taking part in the #100DaysToOffload[a] challenge.
=> https://100daystooffload.com/ [a] => https://100daystooffload.com/ [a]

View file

@ -0,0 +1,73 @@
~~~~~~~~
title: State of Rust GUIs
## date: 2022-03-17
> This post is day 2 of me taking part in the #100DaysToOffload[a] challenge.
=> https://100daystooffload.com/ [a]
The website Are we GUI Yet?[a] helpfully lists a lot of the libraries and frameworks available for making a GUI in Rust. Ive been looking into making a GUI program in Rust, so Ive been working my way through some of these options.
=> https://www.areweguiyet.com/ [a]
This is not a through review, just my thoughts after a brief look. Id recommend looking over the website and deciding for yourself.
## Best candidate: Dioxus
* Website: [a]
=> https://dioxuslabs.com/ [a]
Dioxus is probably the option I like the best from a quick look. Declarative applications similar to React, encapsulated components, first class async support, and good type checking.
Downsides? Right now its web only. Desktop applications are just web applications rendered inside a web view. Thats okay for cross platform apps, but not for what I want to do which is a lightweight native application.
## Better Electron: Tauri
* Website: [a]
=> https://github.com/tauri-apps/tauri [a]
Tauri is a really good replacement for Electron. You can see the comparison on their Github page, smaller binaries, less memory use, and faster launch times.
But again, it is a web app running in a web view. Not a native desktop app. Even though Tauri uses less memory than electron, it still uses ~180 MB according to their comparison. And the fast launch time is still around 0.4 seconds, way longer than what I would expect.
## My current preference: Slint
* Website: [a]
=> https://slint-ui.com/ [a]
I really like Slint. It is a native GUI with their own OpenGL renderer, and an optional Qt backend. From some basic experimentation, it seems to launch in less than 50ms, and uses less than 80 MB of memory (mostly shared libraries).
You can write the code in either .slint files (and they actually have okay editor support for this file type), or inside macros in your code files. The code also looks pretty intuitive.
The downsides? The theming support is not great/nonexistent, you cant dynamically generate UI elements (well kinda, you can generate them based on properties you change at runtime, but the components themselves are hardcoded), and the code sometimes gets awkward due to current limitations.
```MainWindow := Window {
// You then have to bind to this callback inside rust code. No way to just write a hook that calls a rust function.
callback save_to_file(string);
HorizontalLayout {
height: 32px;
FilePath := LineEdit {
placeholder_text: "placeholder here";
}
Button {
text: "Save to file";
clicked => { save_to_file(FilePath.text); }
}
}
}
```
There is also no way to do some things, like setting a dialog hint for your main window, which is something I needed to do.
## Conclusion?
It looks like the state of GUIs in rust is still “not yet”. There are a few more projects I need to look at, like Relm[a], but their code looks way too verbose to me. In the end, I think the best option might be to just write my GUI in C++ with Qt, and maybe integrate bits written in rust inside of that.
=> https://github.com/antoyo/relm [a]