Skip to main content

Module field

Module field 

Source
Expand description

A field’s state, one model for every input (text fields, numbers, paths, sliders): whether it is modified, required, invalid, disabled (and why), read-only or pending.

Experimental: may change in any release (docs/stability.md).

The state is data: a widget draws it (an edge, a marker and an icon per state, never colour alone), gives it to assistive technologies and reports it to agents. Which states a field has comes from the application (validation, what the field depends on); FieldState only says how they combine.

use egui_pop_model::field::{Baseline, FieldState, Mark};

let state = FieldState::new()
    .required()
    .modified(Baseline::Default)
    .invalid("Give a name");
assert!(state.is_editable());
assert_eq!(state.edge(), Some(Mark::Invalid));
assert_eq!(state.marks(), vec![Mark::Invalid, Mark::Modified, Mark::Required]);

let off = FieldState::new().disabled("Needs an open image");
assert!(!off.is_focusable());
assert_eq!(off.disabled_reason(), Some("Needs an open image"));

Structs§

FieldState
A field’s state. The default is a plain field: editable, optional, valid, unchanged.
Modified
How a field is modified.

Enums§

Baseline
What a modified field differs from.
Mark
One state a field shows, for its marker and icon. The order of the variants is the order of precedence: the first state a field has gives its edge.