GUI Struggle with Rust

Challenges I am facing with GUI development in Rust

July 9, 2024
Reading Time: 4 minutes

(This is a continuation of my Journey with Rust)

Rust is an excellent programming language if you want to develop a fast executing software. This is good for me because I needed in multiple calculations in the softwares I develop. However, in order for me to develop software for other users, I needed something easy and user friendly. For this I'm going to need a Graphical User Interface (GUI).

Choices

Rust is an early developing language but there are already a number of choices in terms of GUI programming. However, most of them uses web technologies with rust as backend. I was trying to avoid those and wanted to develop fully native user interfaces. I want my software to be a native-looking to a desktop.

By removing frameworks with web technologies from the picture, I have tried 2 frameworks so far, slint and gtk-rs.

Experience with slint

Slint is a declarative UI toolkit for C++, Rust and Javascript. I have great experience with it for laying our the UI widgets. I have a background in developing with Swift and SwiftUI for MacOS and iOS apps. I can say that in terms of laying out of elements, they are alike in a declarative way. Scoping widgets after widgets.

The UI for me is great in slint, however, I am having difficulty when it coms to closures in the callbacks for the UI events.

To see if there are easier alternatives, I looked at gtk-rs library. I will definitely come back and check on slint though if I will ever have significant issue in gtk-rs.

Experience with gtk-rs

I was in the airport when I decided I wanted to try another framework (July 8, 2024). I looked at wx port of Rust but the development has been abandoned for a few years. I also looked at winapi before slint since I am currently developing for Windows but didn't get a good grasp of the library.

And so I decided to try and setup gtk-rs. And man it's not as easy as just installing a crate in the toml file.

There are a lot of setup needed but thanks to the online slint book, I successfully installed the library and its dependencies.

And so I started building with it. I arrived at South Cotabato and in the evening, tried to run a simple GUI.

The coding for the UI is straightforward, however, I found that I cannot adjust the size of the app bar buttons (minimize, restore, and close). I looked in the internet and found that GTK widgets can be customized using CSS. But that was with the GTK, I am using gtk-rs. So far (July 10, 2024), I have not found a solution yet.

I am still open to finding other UI library for Rust during my free time. I may also update this post if I found some interesting additions to it.

Summary

As of now, I have only tried a total of 2 native GUI frameworks in rust. I am still looking for other alternatives. I may give Druid a try even if the developers have stopped developing it. Also I wanted to try Xilem, a new project by the developers of Druid but it's still in early stage and at the time of writing, it has a tag of 0.1.0. If I cannot find a suitable native GUI framework for my project, I may be resorting to frameworks that uses web technologies.

Conclusion

This is a part of the series for my learning of the Rust programming language. It's tough to learn the language and build something with it, but building a Graphical User Interface is another story. It may require double or triple the time it will take you than in building the library for the software.

If you have any suggestion that may help in building GUIs in rust, that would be much appreciated...