GtkEntry

GtkEntry

GtkEntry is a GTK widget mirrored in XFrame in the “Text & Entry” section, built from the Entry archetype (kind “Entry”). Single-line text editing. It holds editable text, takes keyboard focus, and reports text changes and Enter presses.

Category: XFrame   Family: Gtk   Section: Text & Entry   Archetype: Entry   Kind: Entry   Default size: 180×30

GtkEntry running under Xvfb
GtkEntry 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
textStr—set_text
placeholder-textStr——
max-lengthInt0set_max_length
width-charsInt-1—
editableBooltrueset_editable
visibilityBooltrue—

“—” 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.

Entry archetype settings (Rust)

Settings on the shared Entry 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
alignmentInt—set_alignment
char-caseInt—set_char_case
numbers-onlyBool—set_numbers_only
hide-selectionBool—set_hide_selection
auto-selectBool—set_auto_select
passwordBool—set_password
show-passwordBool—set_show_password
cursor-visibleBool—set_cursor_visible
multilineBool—set_multiline

Working example

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

cargo run -p xframe-demo --example GtkEntry
//! GtkEntry — minimal complete XFrame example.
//!
//! Run it from the workspace root:
//!     cargo run -p xframe-demo --example GtkEntry
//! It opens an 800x600 window showing one GtkEntry 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("GtkEntry")` 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("GtkEntry", false, None, None) {
        Ok(code) => ExitCode::from(code as u8),
        Err(e) => {
            eprintln!("GtkEntry 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.

SignalHandlerWhat it meansKind
changedon_changedText changedSimple
activateon_activateEnter pressed (activate)Simple

Connect changed, activate in the designer; the generated program wires each signal to a stub handler (on_<signal>) you fill in.

Text input: every key press while the entry is focused edits its text; changed fires on each edit and activate when Enter is pressed. Read the current text with text().

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.

Editing text boxes

An entry edits its text with the keyboard once focused: printable keys insert, Backspace deletes, Enter fires activate. In code, set_text(...) replaces the whole contents and text() reads it back. set_max_length(n) caps the length, set_editable(false) makes it read-only, set_password(true) masks the text, and set_show_password(true) reveals it. set_cursor_visible(false) hides the caret.

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