Skip to main content

Module input

Module input 

Source
Expand description

The decorated input: one component around a text, number, path or search field, with what desktop and web toolkits put around a field.

Experimental: may change in any release (docs/stability.md).
  • a placeholder shown while the field is empty (field.tone.muted.text);
  • leading and trailing slots: an icon, a prefix or a suffix text, a unit;
  • a clear ✕, shown while there is a value and the field can be edited, reachable by Tab (Enter or Space presses it); clearing is one change, so one undo step when the field is bound to a store (and one in the field’s own Ctrl+Z history);
  • a reset arrow while the field state offers “reset to default”;
  • attached buttons joined to the field’s end (Browse, a picker), each a button of its own, or a split button: its action and a chevron opening a menu;
  • a dropdown chevron opening a list of choices for the value;
  • the field state drawn as every field draws it (an edge, a marker icon per state, the disabled reason as a tooltip), given to assistive technologies and reported to agents (crate::field).

Two text fields go beyond one visible line of plain text:

  • a masked field (Input::masked: a password, a token, an API key) draws every character as a bullet, cannot be copied or cut from, and gives assistive technologies its name and the password-input role, never its value (the value and the text runs they read are bullets too); agents get its kind (masked), never its value;
  • a multi-line field (Input::multiline) shows rows lines when it is short (2 by default), grows with its text up to max_rows lines (8 by default), then scrolls. Enter starts a new line and Ctrl+Enter (Cmd+Enter on macOS) submits (InputOutput::submitted, the field keeps the focus); with submit_on_enter, Enter submits and Shift+Enter starts a new line, as in a chat box. Ctrl+Enter is a key binding’s when the keymap binds it (the dispatcher leaves only Escape and Enter without Ctrl or Alt to a text field). Tab still moves the focus; the slots, the buttons and the markers stay on the first line.

The field itself is egui’s TextEdit, so it follows the focus rules of every text input: while it has the focus, Escape and Enter are its own (Escape leaves the field, Enter commits it), and no key binding fires on them. A number field commits the value typed (a number or an expression, as a slider’s typed entry reads it) when it loses the focus, except to Escape, which drops what was typed.

Every part that takes the focus joins the Tab order of the crate::tab scope it is drawn in, as one group: the field, then its buttons. A disabled input is skipped; a read-only one is not.

use egui_pop_core::icon::Icon;
use egui_pop_core::input::{Attached, Input};
use egui_pop_model::field::FieldState;

fn row(ui: &mut egui::Ui, query: &mut String, folder: &mut String, iso: &mut f64) {
    Input::search(query, "Search").placeholder("Search photos").show(ui);
    let out = Input::path(folder, "Folder")
        .button(Attached::text("Browse…", "Browse for a folder"))
        .state(FieldState::new().required())
        .show(ui);
    if out.button == Some(0) { /* open a file dialog */ }
    Input::number(iso, "ISO").unit("ISO").choices(["100", "400", "1600"]).show(ui);
}

fn account(ui: &mut egui::Ui, token: &mut String, notes: &mut String) {
    Input::masked(token, "API token").show(ui);
    let out = Input::multiline(notes, "Notes").rows(3).max_rows(6).show(ui);
    if out.submitted { /* Ctrl+Enter: send the notes */ }
}

Structs§

Attached
A button joined to the field’s end.
Input
A decorated input (see the module).
InputOutput
What an input did in a frame.
SplitOutput
What a split button did.

Enums§

Kind
What a field edits.
Slot
Something drawn inside the field, before or after the value.

Functions§

split_button
A split button on its own: an action (text) and a chevron opening a menu of items. Both parts take the focus and join the Tab order.