Skip to main content

Module hex_color_input

Module hex_color_input 

Source
Expand description

HexColorInput — single-line #RRGGBB[AA] color editor.

A specialization of TextInput that wires an input mask, a hex-digit character filter, and a strict commit-time validator on top of the standard text-editing surface. Bound to a Signal<Color> (required) or Signal<Option<Color>> (nullable). External writes to the bound signal reformat the field text — but only when the field is unfocused, so a user typing “FF” in the middle of a long color code isn’t clobbered by a sibling widget tweaking the value.

§Behaviour

  • Parsing: #RRGGBB (case-insensitive); #RRGGBBAA if alpha_enabled; #RGB short-form expands to #RRGGBB if short_form_enabled. Each accepted form may be normalized to uppercase on commit (configurable).
  • Char filter: only [0-9a-fA-F#] admitted while typing.
  • Mask: \\#hhhhhh (or \\#hhhhhhhh with alpha) — the TextInputField mask grammar (h = hex digit slot, \\ literal escape).
  • Validation: commits on Enter / Tab-out / blur. Returns ValidationOutcome::Valid / ValidationOutcome::Corrected / ValidationOutcome::Invalid which the inner field maps to a visible inline strip via the standard validation_feedback bridge.
  • Nullable: empty (after trim) commits None; non-empty parses normally and commits Some(color).

§Example

let color = ctx.signal(Color::from_hex("#3584E4"));
ctx.add(
    HexColorInput::new(color)
        .alpha_enabled(true)
        .label("Background"),
);

Structs§

HexColorInput
Single-line hex color editor.