GTK Integration
Font Family Crates
Each font family crate provides a register_glyphs() function (enabled with
the gtk feature) that registers the compiled GResource bundle:
use fonts_rs_doto::register_glyphs;
fn main() {
// Register GResource (call once at startup)
register_glyphs().unwrap();
// Now GTK can resolve icon names from the GResource bundle
let image = gtk4::Image::from_icon_name("doto-a");
}
register_glyphs() calls gio::resources_register_include!("icons.gresource")
to register the compiled GResource binary containing all SVG glyph files.
Nerd Fonts (nerd-fonts-rs)
The nerd-fonts-rs crate provides additional GTK4 functionality:
Initialization
Call init() once at application startup:
use nerd_fonts_rs::init;
fn main() {
init(None);
// ...
}
init() performs the following:
- Font initialization (with
renderfeature) - Sets the font search base directory - GResource registration - Registers the compiled GResource binary
- Icon registration - Registers vendored Nerd Font SVG icons
- CSS loading - Loads version-adapted
@font-faceCSS viafont_face_css()into aCssProviderand adds it to the default display
GTK Icon Name Resolution
#![allow(unused)]
fn main() {
use nerd_fonts_rs::gtk::resolve_gtk_nerd_icon;
let icon_name = resolve_gtk_nerd_icon("nf-fa-gamepad");
// Returns "nf-fa-gamepad-symbolic"
let image = gtk4::Image::from_icon_name(&icon_name.unwrap());
}
The function normalizes CSS class names (like nf-fa-gamepad or fa-gamepad)
into GTK icon names that gtk4::Image::from_icon_name understands.