This is a premium alert message you can set from Layout! Get Now!

The state of Rust GUI libraries

0

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 have used Rust for things like systems design, web development, and building GUIs. You can use many packages and crates to develop fast, complex GUI applications in Rust.

In this article, we’ll talk about popular Rust GUI libraries and frameworks like gtk-rs, fltk-rs, iced, relm, Azul, and egui. We’ll also compare these GUI libraries and discuss how they’re a good choice for building your GUI application.

Let’s get started!

The gtk-rs library

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, such as 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 provides GTK 3 and GTK 4 functionalities, respectively.

Gtk-rs Library

To get started using the gtk-rs libraries, you 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 gtk4 and adding it to your dependencies, you can import the crate like this:

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.

The GTK library is popular in the developer community. 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.

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 looks 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.

Fltk-rs Crate

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.

You can install the fltk library using this brew command if you’re on a macOS or Linux computer:

brew install fltk

You can find instructions for installing the fltk library for other operating systems on the linked page. 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:

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 and has more than 800 stars. It’s growing fast with more than 200 releases at this time and you can use the library in production without concerns.

According to many other developers, using the fltk-rs library is more straightforward than the C++ library.

The iced library

iced is a renderer-agnostic, batteries included, data-centered cross-platform Rust library for building GUIs and frontends, inspired by the Elm Architecture. The iced library provides an easy-to-use, reactive programming model with first-class support for async actions and custom widgets.

The Iced Library

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: for the state of the application
  • Messages: for messages and events
  • View logic: for displaying states as widgets for user interactions
  • Update logic: for 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.

The iced library is one of the most popular Rust libraries due to its versatility. Although the library is used in many projects, it’s pretty unstable and has a rapid development. You can resort to using older releases, as the master branch is constantly changing and might be expensive to use in production.

You can find projects for inspiration, code examples, and library implementations in this repository.

The relm library

relm is a GTK-based, asynchronous GUI library written initially in Rust. 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.

The Relm Library

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"

You also have to 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. The relm library is in its beta stage, hasn’t been appropriately tested, and is changing rapidly. With this 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++. It’s powered by WebRender and 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

The Azul framework also provides lots of inbuilt widgets, more than 60 frames per second animations, 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:

[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.

The egui library

The egui library 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). It’s aiming to be the easiest library for building web applications in Rust.

The Egui Library

The egui library aims to provide a safe, responsive, friendly, and portable experience for building GUIs with no callbacks and minimal dependencies. Check out egui’s official documentation to learn how you can use it to make cross-platform GUIs.

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 have different features and functionalities. Here’s a comparison table between the GUI libraries to help you 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

The GUI libraries in the Rust ecosystem are mostly premature projects with a lot of good features.

For your projects, you’ll want to consider the state of the project for your application. It’s risky to use untested libraries or ones that aren’t production-ready. You’ll also want to consider the project’s compatibility based on what you’re building and where the project will or should run.

As an example, the iced library is popular because it can run on Windows, Linux, macOS, and the web. It could be a good choice to use since your apps can share similarities and would be easier to maintain. The gtk-rs library is also lovely considering the library’s legacy. Additionally, you can use the relm library if you want to go the Elm way.

Conclusion

There are many other GUI libraries in the Rust ecosystem, and you can find a comprehensive list on Are We GUI Yet and LibHunt.

This tutorial taught you about popular GUI libraries in the Rust ecosystem, including gtk-rs to fltk-rs, iced, relm, Azul, and egui.

Hopefully, this tutorial has helped you with insights into choosing the GUI library for your next project!

The post The state of Rust GUI libraries appeared first on LogRocket Blog.



from LogRocket Blog https://ift.tt/4nRmwHK
Gain $200 in a week
via Read more

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment

Search This Blog

To Top