41 releases

0.9.1 Oct 11, 2024
0.9.0 Jul 12, 2024
0.8.1 Mar 13, 2024
0.7.0-beta.2 Oct 14, 2023
0.4.0-beta.2 Nov 26, 2021

#11 in GUI

Download history 2407/week @ 2024-08-10 2349/week @ 2024-08-17 2099/week @ 2024-08-24 2308/week @ 2024-08-31 2375/week @ 2024-09-07 2608/week @ 2024-09-14 4383/week @ 2024-09-21 3024/week @ 2024-09-28 3010/week @ 2024-10-05 3274/week @ 2024-10-12 3290/week @ 2024-10-19 2695/week @ 2024-10-26 3503/week @ 2024-11-02 3826/week @ 2024-11-09 3963/week @ 2024-11-16 2659/week @ 2024-11-23

14,441 downloads per month
Used in 25 crates (16 directly)

Apache-2.0 OR MIT

390KB
8K SLoC

Relm4

CI Matrix Relm4 on crates.io Relm4 docs Relm4 book Minimum Rust version 1.75 dependency status

An idiomatic GUI library inspired by Elm and based on gtk4-rs. Relm4 is a new version of relm that's built from scratch and is compatible with GTK4 and libadwaita.

Why Relm4

We believe that GUI development should be easy, productive and delightful.
The gtk4-rs crate already provides everything you need to write modern, beautiful and cross-platform applications. Built on top of this foundation, Relm4 makes developing more idiomatic, simpler and faster and enables you to become productive in just a few hours.

Our goals

  • ⏱️ Productivity
  • Simplicity
  • 📎 Outstanding documentation
  • 🔧 Maintainability

Documentation

Dependencies

Relm4 depends on GTK4: How to install GTK4 and Rust

Ecosystem

Use this in to your Cargo.toml:

# Core library
relm4 = "0.9"
# Optional: reusable components
relm4-components = "0.9"
# Optional: icons (more info at https://github.com/Relm4/icons)
relm4-icons = "0.9.0"

Features

The relm4 crate has four feature flags:

Flag Purpose Default
macros Enable macros by re-exporting relm4-macros
libadwaita Improved support for libadwaita -
libpanel Improved support for libpanel -
gnome_46 Enable all version feature flags of all dependencies to match the GNOME 46 SDK -
gnome_45 Enable all version feature flags of all dependencies to match the GNOME 45 SDK -
gnome_44 Enable all version feature flags of all dependencies to match the GNOME 44 SDK -
gnome_43 Enable all version feature flags of all dependencies to match the GNOME 43 SDK -
gnome_42 Enable all version feature flags of all dependencies to match the GNOME 42 SDK

The macros feature is a default feature.

Examples

Several example applications are available at examples/.

📸 Screenshots from the example apps

A simple counter app

Simple app screenshot light Simple app screenshot dark

use gtk::prelude::*;
use relm4::prelude::*;

struct App {
    counter: u8,
}

#[derive(Debug)]
enum Msg {
    Increment,
    Decrement,
}

#[relm4::component]
impl SimpleComponent for App {
    type Init = u8;
    type Input = Msg;
    type Output = ();

    view! {
        gtk::Window {
            set_title: Some("Simple app"),
            set_default_size: (300, 100),

            gtk::Box {
                set_orientation: gtk::Orientation::Vertical,
                set_spacing: 5,
                set_margin_all: 5,

                gtk::Button {
                    set_label: "Increment",
                    connect_clicked => Msg::Increment,
                },

                gtk::Button {
                    set_label: "Decrement",
                    connect_clicked => Msg::Decrement,
                },

                gtk::Label {
                    #[watch]
                    set_label: &format!("Counter: {}", model.counter),
                    set_margin_all: 5,
                }
            }
        }
    }

    // Initialize the component.
    fn init(
        counter: Self::Init,
        root: Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let model = App { counter };

        // Insert the code generation of the view! macro here
        let widgets = view_output!();

        ComponentParts { model, widgets }
    }

    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
        match msg {
            Msg::Increment => {
                self.counter = self.counter.wrapping_add(1);
            }
            Msg::Decrement => {
                self.counter = self.counter.wrapping_sub(1);
            }
        }
    }
}

fn main() {
    let app = RelmApp::new("relm4.example.simple");
    app.run::<App>(0);
}

Projects using Relm4

  • fm — A small, general-purpose file manager.
  • Done - A simple and versatile to do app.
  • Reovim - GUI frontend for neovim.
  • NixOS Configuration Editor - A graphical configuration editor for NixOS.
  • Rhino Setup - Setup wizard for Rolling Rhino
  • Lemoa - Desktop client for Lemmy
  • Score Tracker - App for tracking player scores in card and board games
  • Spidey - A seamless and distraction-free work and play environment on the web
  • Toolbox Tuner - An application to manage Toolbx containers
  • BitRitter - A bitwarden/vaultwarden client with mobile devices in mind
  • Space Acres - An opinionated GUI application for farming on Autonomys Network

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Feedback and contributions are highly appreciated!

Dependencies

~18–27MB
~509K SLoC