diff --git a/content/state-of-rust-GUIs.md b/content/state-of-rust-GUIs.md new file mode 100644 index 0000000..91089d5 --- /dev/null +++ b/content/state-of-rust-GUIs.md @@ -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.