#gui #gtk #gtk4

relm4

An idiomatic GUI library inspired by Elm and based on gtk4-rs

11 releases

0.2.1 Oct 17, 2021
0.2.0 Oct 9, 2021
0.1.0 Sep 6, 2021
0.1.0-beta.9 Aug 24, 2021

#33 in GUI

Download history 111/week @ 2021-08-10 83/week @ 2021-08-17 31/week @ 2021-08-24 14/week @ 2021-08-31 115/week @ 2021-09-07 23/week @ 2021-09-14 12/week @ 2021-09-21 21/week @ 2021-09-28 60/week @ 2021-10-05 64/week @ 2021-10-12 27/week @ 2021-10-19

172 downloads per month
Used in relm4-components

Apache-2.0 OR MIT

575KB
1.5K SLoC

Relm4

CI Matrix Relm4 on crates.io Relm4 docs Relm4 book Minimum Rust version 1.54

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.

Ecosystem

Relm4 has two crates that extend the core functionality:

  • relm4-macros provides a widget macro that simplifies UI creation
  • relm4-components is a collections of reusable components you can easily integrate into your application

Add this to your Cargo.toml:

gtk = { version = "0.3", package = "gtk4" }
relm4 = "0.2"
relm4-macros = "0.2"
relm4-components = "0.2"

Features

The relm4 crate has two feature flags:

  • tokio-rt: Adds the AsyncWorker type that uses an async update function
  • libadwaita: Improved support for libadwaita

Examples

Several example applications are available at relm4-examples/.

📸 Screenshots from the example apps

A simple counter app

Simple app screenshot light Simple app screenshot dark

use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt};
use relm4::{send, AppUpdate, Model, RelmApp, Sender, WidgetPlus, Widgets};

#[derive(Default)]
struct AppModel {
    counter: u8,
}

enum AppMsg {
    Increment,
    Decrement,
}

impl Model for AppModel {
    type Msg = AppMsg;
    type Widgets = AppWidgets;
    type Components = ();
}

impl AppUpdate for AppModel {
    fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
        match msg {
            AppMsg::Increment => {
                self.counter = self.counter.wrapping_add(1);
            }
            AppMsg::Decrement => {
                self.counter = self.counter.wrapping_sub(1);
            }
        }
        true
    }
}

#[relm4_macros::widget]
impl Widgets<AppModel, ()> for AppWidgets {
    view! {
        gtk::ApplicationWindow {
            set_title: Some("Simple app"),
            set_default_width: 300,
            set_default_height: 100,
            set_child = Some(&gtk::Box) {
                set_orientation: gtk::Orientation::Vertical,
                set_margin_all: 5,
                set_spacing: 5,

                append = &gtk::Button {
                    set_label: "Increment",
                    connect_clicked(sender) => move |_| {
                        send!(sender, AppMsg::Increment);
                    },
                },
                append = &gtk::Button {
                    set_label: "Decrement",
                    connect_clicked(sender) => move |_| {
                        send!(sender, AppMsg::Decrement);
                    },
                },
                append = &gtk::Label {
                    set_margin_all: 5,
                    set_label: watch! { &format!("Counter: {}", model.counter) },
                }
            },
        }
    }
}

fn main() {
    let model = AppModel::default();
    let app = RelmApp::new(model);
    app.run();
}

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

~16MB
~390K SLoC