Graphical user interfaces (GUIs) provide an intuitive visual frontend for interacting with computers. GUIs use visual indicators like icons, windows, and menus for better user interaction and experience, unlike command-line interfaces (CLIs) that use text for input and output operations.
Rust has been growing in popularity over time, likely due to its flexibility and vibrant open source community. Developers use Rust for things like systems design, web development, and building GUIs. There are many packages and crates available for developing fast, complex GUI applications in Rust.
In this article, we’ll review a few popular Rust GUI libraries and frameworks, including Tauri, Druid, Slint, gtk-rs, fltk-rs, iced, relm, Azul, and egui. We’ll also compare these GUI libraries, discussing when they’re a good choice for building your GUI application. Let’s get started!
- Tauri
- Druid
- Slint
- gtk-rs
- The fltk-rs crate
- iced
- relm
- The Azul framework
- egui
- Comparing Rust GUI libraries
Tauri
Tauri is an open source package that enables developers to create lightweight, web-based desktop applications using the Rust programming language.
Tauri leverages JavaScript, WebAssembly, and other web technologies to create a seamless development experience. Tauri provides a simple API for creating and customizing desktop applications, making it easy for developers to build cross-platform applications that run on Windows, Mac, and Linux:
One critical feature of the Tauri package is its cross-platform compatibility. With Tauri, you can create a single GUI that can run on multiple platforms with minimal modification, resulting in a “build for one, run on all” scenario.
Thanks to its web-based architecture, Tauri applications are lightweight and fast. Tauri runs on web technologies, and apps run smoothly on low-end hardware.
Finally, Tauri uses an event-driven architecture that allows for easy interaction with events. Tauri provides access to native APIs and JavaScript interoperability that enables the packages to access JavaScript functions from Rust code.
Adding Tauri to your project is simple; you just need to add the package to the dependencies
section of the Cargo.toml
file in your project’s root directory:
[dependencies] tauri = "0.9.0"
Once you’ve added Tauri as a project dependency, you can import it into your Rust file by adding the following code to the top of your file:
use tauri::{Builder, Tauri};
Tauri offers many features and functionalities for creating web-based desktop applications. With Tauri’s simple API, cross-platform compatibility, and focus on performance and security, Tauri is an excellent choice for developers looking to build robust and reliable graphical user interfaces with Rust.
Druid
N.B., Druid’s maintainers have indicated that it is being discontinued in favor of other projects based on the same general principles, such as Xilem.
Druid is a powerful and flexible Rust library for building GUIs for desktop applications. One of the critical features of Druid is the layout system, which allows for easy and intuitive widget layout based on constraints, making it easy to create visually consistent and responsive user interfaces.
Druid also provides a wide range of built-in widgets, including buttons, labels, and text inputs that you can use to customize the look and feel of your application with support for custom widgets:
Druid is cross-platform compatible, with support for Windows, macOS, and Linux, allowing you to write your application once and run it on multiple platforms without any modifications. Druid also provides a comprehensive event-handling system that makes it easy to respond to user interactions and update user interfaces in real time.
To get started with the Druid package, add the following code to the dependencies
in your cargo.toml
file:
[dependencies] druid = "0.7.0"
To import Druid into a Rust file, use the following code:
use druid::{AppLauncher, WindowDesc};
Druid is a powerful and versatile GUI library that is well-suited for building high-performance, cross-platform desktop applications in Rust. With its wide range of built-in widgets, intuitive layout system, and extensive documentation, Druid makes it easy to create visually appealing and responsive user interfaces for your Rust applications.
Slint
Slint is an open source, Rust-based UI framework for building native user interfaces. Slint provides a comprehensive yet simple solution for building applications for embedded devices, microcontrollers, and desktop:
One of Slint’s key features is its support for multiple programming languages. Developers can combine Slint-based GUIs with backend logic written in either Rust, C++, or JavaScript. It also comes with a wide variety of prebuilt UI components, like buttons, forms, modals, and more, so developers don’t have to spend time building them from scratch. The prebuilt components are also customizable, so you can adapt them to the specific needs of your application.
In addition to being responsive across different screen sizes, Slint is cross-platform across different operating systems and processor architectures. Finally, Slint includes a robust set of APIs for building custom components.
To install the Slint package, add the following code to the dependencies
section in your cargo.toml
file:
[dependencies] slint = "1.0.2"
There are various ways to include Slint files in Rust. The most straightforward way is to inline the .slint
code using the slint!
macro:
fn main() { MainWindow::new().unwrap().run().unwrap(); } slint::slint! { export component MainWindow inherits Window { Text { text: "hello world"; color: green; } } }
Overall, Slint is a powerful and versatile solution for building native applications in Rust. Its prebuilt components, responsive design, and custom component APIs make it a valuable tool for any Rust developer working on desktop and embedded projects.
gtk-rs
GTK is a popular, cross-platform, object-oriented widget toolkit developed by The GNOME Project. It’s used for building portable GUI applications that work on Unix, Windows, and macOS systems in a number of languages, from Python to JavaScript, C, and Rust.
There are various versions of the GTK project, like GTK 3, with changes and upgrades to each version.
The gtk-rs project provides safe Rust bindings for GNOME stack-based libraries, like the GTK 3 and GTK 4 libraries. The gtk3-rs
and gtk4-rs
libraries provide GTK 3 and GTK 4 functionalities, respectively:
To get started using the gtk-rs libraries, you’ll need the Rust toolchain and the GTK library. After creating a project, add the library to your dependencies in the Cargo.toml
file for the GTK 4 crate:
gtk = { version = "X.X", package = "gtk4" }
If you’re on macOS or Linux, install the GTK 4 library using the brew package manager:
brew install gtk4
Check these pages for installation instructions on the various Linux Distros and Windows. After installing GTK 4 and adding it to your dependencies, you can import the crate as follows:
use gtk::prelude::*; use gtk::Application;
The gtk-rs book is a good resource for learning how to build GUIs in Rust using the library.
Within the developer community, the GTK library is very popular; many popular Linux GUI applications use the GTK library and GNOME stack. The gtk-rs library is just one of the many Rust GUI libraries ready for production and has been used in more than 500 projects at the time of writing.
The fltk-rs crate
FLTK (Fast Light Toolkit) is a lightweight, cross-platform-supported toolkit for building GUIs. FLTK is supported on Windows, macOS, and UNIX systems and was originally built for C++. If you use the FLTK toolkit to create a GUI application, the application will look the same on all supported operating systems.
The fltk-rs library provides Rust bindings for the FLTK toolkit. The fltk-rs crate supports old architecture with more than 80 customizable widgets and more than four supported theme schemes, including the GTK scheme. You can also use the fltk-theme crate for more customizations:
The fltk-rs library is quick to install, build, start, and run with a single execution. Getting started with the fltk-rs crate is easy; all you have to do is add the project as a dependency to your Cargo.toml
file and install the library on your computer.
If you’re on a macOS or Linux computer, you can install the fltk library using the following brew command:
brew install fltk
For other operating systems, you can find instructions for installing the fltk library in the docs. Next, add the project as a dependency to your Cargo.toml
file:
[dependencies] fltk = { version = "^1.3", features = ["fltk-bundled"] }
After adding the project and installing the fltk library, you can import the crate into your project as follows:
use fltk::{app, button::Button, frame::Frame, prelude::*, window::Window};
Check out the fltk-rs documentation for a detailed overview of its functionalities and uses. The fltk library is quite popular with more than 800 stars on GitHub at the time of writing. fltk is growing fast, with more than 200 releases, and you can use the library in production without concerns.
According to many developers, using the fltk-rs library is more straightforward than the C++ library.
iced
Inspired by the Elm Architecture, iced is a renderer-agnostic, batteries included, data-centered cross-platform Rust library for building GUIs and frontends. iced provides an easy-to-use, reactive programming model with first-class support for async actions and custom widgets:
GUI applications built with the iced library can run on Windows, macOS, Linux, and the web (using the DOM) with a responsive layout. Conventionally, iced splits applications into four concepts:
- State: The state of the application
- Messages: Messages and events
- View logic: Displaying states as widgets for user interactions
- Update logic: Updating state and interacting with messages
You can easily get started using the iced library for frontend web applications. The process is similar to building GUI applications, and you can check out the iced documentation to learn more about the package.
Due to its versatility, the iced library is one of the most popular Rust libraries. Despite being used in many projects, iced is somewhat unstable and is undergoing rapid development. However, the master branch is constantly changing and might be expensive to use in production. You may consider using older releases.
You can find projects for inspiration, code examples, and library implementations in this repository.
relm
Initially written in Rust, relm is a GTK-based, asynchronous GUI library. It’s inspired by the Elm Architecture to simplify GTK library usage and provide an Elm-like experience.
Like the GTK library, you can build cross-platform GUIs using relm:
You’ll need to have experience using the GTK library to use relm and get the most out of the library.
To use relm, you need to add the gtk and relm libraries to your project’s dependencies in your Cargo.toml
file. You’ll also need to have the gtk library installed:
[dependencies] gtk = "0.9.0" relm = "0.20.0" relm-derive = "0.20.0"
Finally, import the gtk crate alongside the relm crates:
use relm::{connect, Relm, Update, Widget}; use gtk::prelude::*; use gtk::{Window, Inhibit,a WindowType}; use relm_derive::Msg;
The Rust community appreciates relm for the Elm-like experience that other Rust libraries, like Yew, Seed, and iced, provide.
At the time of writing, relm is in its beta stage, meaning it hasn’t been appropriately tested and is changing rapidly. With that said, you may not want to use it in production just yet.
The Azul framework
The Azul framework is a reactive GUI library for building desktop GUIs in Rust, C, and C++. Powered by WebRender, Azul is a document object model, similar to HTML and CSS. Since Azul leverages WebRender, it provides features like gradients, box shadows, border styling, and CSS transforms:
The Azul framework also provides lots of inbuilt widgets, more than 60 frames per second animation, cross-platform native dialogues, SVG parsing, dynamic linking through the shared library, and HTML to Rust compilation for hot reloads.
To get started using the Azul framework, add it to your project’s dependencies as follows:
[dependencies] azul = "1.0.0-alpha"
Then, import the crates to your project and use them:
use azul::prelude::*; use azul::widgets::{button::Button, label::Label};
The Azul framework is well-documented to help you get started building GUIs.
The Azul framework takes a different approach to GUI development, and, so far, the framework has been used in more than 200 Rust projects. The Azul framework is functional, and, according to the documentation, you can use it in production.
egui
egui is an immediate-mode, easy-to-use, portable library for building GUIs in Rust that run on the web, computers, and game engines in development. egui is aiming to be the easiest library for building web applications in Rust:
egui aims to provide a safe, responsive, friendly, and portable experience for building GUIs with no callbacks and minimal dependencies. To learn how you can use it to make cross-platform GUIs, check out egui’s official documentation.
The egui library is in active development, and, if you’re brave enough, you can use it in production. Specific parts of the egui library are ready, and you can resort to older releases since newer ones are prone to breaking changes.
Comparing Rust GUI libraries
The GUI libraries discussed in this article each offer different features and functionalities. The comparison table below will help you to make choices and considerations for your next project:
Production-ready | Compatibility | |
---|---|---|
gtk-rs | Yes | Cross-platform |
fltk-rs | Yes | Cross-platform |
iced | No | Cross-platform and web |
relm | No | Cross-platform |
Azul | Yes | Cross-platform |
egui | Older Releases | Cross-platform |
Tauri | Yes | Desktop and web |
Slint | Yes | Cross-platform and web (for demo purposes) |
Druid | Yes | Desktop and web |
Many of the GUI libraries in the Rust ecosystem are premature projects with a lot of good features. Be sure to consider the state of the library for your project; it’s risky to use untested libraries.
You’ll also want to consider the library’s compatibility based on what you’re building and where the project will run. It’s always recommended to thoroughly test and evaluate any library or tool before using it in a production environment.
Conclusion
There are many other GUI libraries in the Rust ecosystem; you can find a comprehensive list on Are We GUI Yet and LibHunt. In this tutorial, we explored several popular GUI libraries in the Rust ecosystem, including Druid, Slint, Tauri, gtk-rs, fltk-rs, iced, relm, Azul, and egui. Hopefully, this tutorial has given you some insight into choosing the best GUI library for your next project!
LogRocket: Full visibility into web frontends for Rust apps
Debugging Rust applications can be difficult, especially when users experience issues that are difficult to reproduce. If you’re interested in monitoring and tracking performance of your Rust apps, automatically surfacing errors, and tracking slow network requests and load time, try LogRocket.
LogRocket is like a DVR for web and mobile apps, recording literally everything that happens on your Rust app. Instead of guessing why problems happen, you can aggregate and report on what state your application was in when an issue occurred. LogRocket also monitors your app’s performance, reporting metrics like client CPU load, client memory usage, and more.
Modernize how you debug your Rust apps — start monitoring for free.
If you utilise Bevy, you can have egui render on the web.
the best for production is not listed: Tauri
How can druid not be listed?
No mention of Slint (formerly SixtyFPS).