GtkLabel

GtkLabel

GtkLabel is a GTK widget mirrored in XFrame in the “Display” section, built from the Label archetype (kind “Label”). Static text. It displays a string, optionally wrapped or aligned, and does not take keyboard input.

Category: XFrame   Family: Gtk   Section: Display   Archetype: Label   Kind: Label   Default size: 180×30

GtkLabel running under Xvfb
GtkLabel running in an 800×600 window under Xvfb.

Properties

PropertyTypeDefaultRust setter
backgroundColor—set_style_name
foregroundColor—set_style_name
tooltip-textStr——
visibleBooltrueset_visible
enabledBooltrueset_enabled
labelStr—set_text
xalignDouble0.5set_xalign
selectableBoolfalse—
wrapBoolfalse—

“—” in the setter column means the Rust widget code has no setter for that property: it is set in the designer (Inspector) and carried in the saved design, not changed from Rust code.

Label archetype settings (Rust)

Settings on the shared Label struct in crates/xframe-widgets/src/archetypes.rs. One struct serves every kind of the archetype, so only the settings matching this kind apply to it (a calendar uses set_date, a notebook uses the tab settings, a grid uses the grid settings). “—” as a default means the data gives no Inspector default for that setting.

PropertyTypeDefaultRust setter
yalignDouble—set_yalign
transparentBool—set_transparent
show-accel-charBool—set_show_accel_char
focus-controlStr—set_focus_control

Working example

Minimal complete Rust program — this is the file examples/GtkLabel.rs in lightgui_rust. Run it with:

cargo run -p xframe-demo --example GtkLabel
//! GtkLabel — minimal complete XFrame example.
//!
//! Run it from the workspace root:
//!     cargo run -p xframe-demo --example GtkLabel
//! It opens an 800x600 window showing one GtkLabel widget (press Esc
//! or `q`, or close the window, to quit). The widget is the real
//! `xframe-widgets` implementation for this registry kind, created by
//! `xframe_widgets::create("GtkLabel")` inside `xframe_demo::run_widget`
//! — the same code path the `xframe-demo` binary uses.

use std::process::ExitCode;

fn main() -> ExitCode {
    match xframe_demo::run_widget("GtkLabel", false, None, None) {
        Ok(code) => ExitCode::from(code as u8),
        Err(e) => {
            eprintln!("GtkLabel example: {}", e);
            ExitCode::from(1)
        }
    }
}

Event handling

Every XFrame widget dispatches the same four input events through the Widget trait: button press, button release, pointer motion, and key press. The generated event loop routes a release to the widget that got the press (even if the pointer moved off it), motion to the pressed widget while dragging and otherwise to the topmost widget under the pointer, and keys only to the focused widget. A press that starts and ends inside an enabled widget fires its click handler (on_click); Return or Space fires it when the widget is focused.

This kind has no named signal of its own in the event tables: it uses the generic press / release / motion / key dispatch above, and its click handler where the archetype provides one.

Font and labels

Change the displayed text at any time with set_text("...") — the widget redraws with the new label. The font comes from the active style: styles are registered on the StyleManager with add_style_ex(name, fill, outline, text, line, radius, line_width, font), and a widget switches style with set_style_name("dark"). So a font change is a style change: register a style with the font you want and apply it by name.

Styling: colours, border radius, line width, line colour

Styling is per-style, not per-widget: a Style carries fill_color, outline_color, line_color, text_color, radius (border radius), line_width, and font_name. Register a style with add_style_ex (argument order: fill, outline, text, line, radius, line width, font) and apply it with set_style_name("name") on any widget — the same widget can be square or rounded, thin- or thick-lined, just by switching style. The demo's default style uses radius 6 and line width 1; dark is the dark variant.


All Rust widgets · lightgui_rust on GitHub

Read more