21 unstable releases (4 breaking)

new 0.10.0-beta.2 Dec 4, 2024
0.10.0-beta.1 Oct 30, 2024
0.9.0 Jul 12, 2024
0.8.2 Mar 13, 2024
0.6.0-beta.6 Mar 24, 2023

#212 in GUI

Download history 387/week @ 2024-08-21 325/week @ 2024-08-28 408/week @ 2024-09-04 668/week @ 2024-09-11 438/week @ 2024-09-18 271/week @ 2024-09-25 176/week @ 2024-10-02 191/week @ 2024-10-09 176/week @ 2024-10-16 265/week @ 2024-10-23 493/week @ 2024-10-30 332/week @ 2024-11-06 275/week @ 2024-11-13 256/week @ 2024-11-20 334/week @ 2024-11-27 762/week @ 2024-12-04

1,679 downloads per month
Used in 5 crates

(Apache-2.0 OR MIT) AND CC0-1.0 AND MIT

160KB

Relm4 icons - Icons for your gtk-rs and Relm4 applications!

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

More than 3000 icons, ready for use in your app!

Usage

1. Find your icons 🔍

You can either use the of the over 3000 shipped icons or your own icons. You can browse the shipped icons using one of the following methods:

For icons from the GNOME icon-development-kit:

For icons from Fluent UI System Icons:

For browsing all shipped icons:

Sometimes, icons-development-kit and Fluent UI System Icons have overlapping icon names, so the postfix "-alt" is added.

2. Add Relm4 icons ✍

relm4-icons = "0.10.0-beta.1"

[build-dependencies]
relm4-icons-build = "0.10.0-beta.1"

3. Add the icons to your project 📦

Add the following to your build.rs:

fn main() {
    relm4_icons_build::bundle_icons(
        // Name of the file that will be generated at `OUT_DIR`
        "icon_names.rs",
        // Optional app ID
        Some("com.example.myapp"),
        // Custom base resource path:
        // * defaults to `/com/example/myapp` in this case if not specified explicitly
        // * or `/org/relm4` if app ID was not specified either
        None::<&str>,
        // Directory with custom icons (if any)
        None::<&str>,
        // List of icons to include
        [
            "ssd",
            "size-horizontally",
            "cross",
        ],
    );
}

4. Load the icons 🛫

Add this to your initialization code:

mod icon_names {
    include!(concat!(env!("OUT_DIR"), "/icon_names.rs"));
}

fn main() {
    ///...///
    relm4_icons::initialize_icons(icon_names::GRESOURCE_BYTES, icon_names::RESOURCE_PREFIX);
}

5. Use the icons 🎉

Use set_icon_name and similar methods to use your icons, for example with ButtonExt, StackPage, MenuButton or Image.

Example

let button = gtk::Button::default();
button.set_icon_name("plus");

You can also use the icon_names module for extra compile-time generated icon names.

use crate::icon_names;

let button = gtk::Button::default();
button.set_icon_name(icon_names::PLUS);

How it works

Crate

  1. Collect all icons specified in the config file
  2. Build a gresource bundle containing only the selected icons
  3. Include the gresource file in the compiled binary
  4. On initialization load the gresource file

Add new icons

To add new icons, move them into the icons folder and make sure their file name ends with -symbolic.svg. Then run the following commands:

cd update_icons
cargo run

Existing icon sets can be updated as submodules with following commands:

git submodule update --remote --checkout
rm -rf build_icons/icons/fluentui-system-icons
rm -rf build_icons/icons/icon-development-kit
cd update_icons
cargo run --bin fetch_icons
cargo run

Credit

  • GNOME contributors for providing so many outstanding icons
  • gvdb-rs for providing a great crate for interacting with gresources in pure Rust
  • gtk-rs for outstanding Rust bindings for GTK4

The source code of Relm4 icons is licensed under the terms of both the MIT license and the Apache License (Version 2.0).

Icons

  • The icons in the icons/icon-development-kit folder are licensed under the terms of the CC0 license and therefore public domain.
  • The icons in the icons/fluentui-system-icons folder are licensed under the terms of the MIT license.

Both licenses should work for both open source and proprietary applications (without warranty).

Dependencies

~15–23MB
~438K SLoC