Phosphor::InputMock
Inherits Phosphor::MockWidget < Reference < Object
A single-line text input primitive.
Generic and app-agnostic: no knowledge of AppState, Msg, or the
application theme. The Widget wrapper resolves theme → Style values
and sets them in Props before each render. The cursor position and
horizontal scroll offset are owned by this widget's WidgetState; the
text value lives in Props and is updated by Cmd::InsertChar /
Cmd::DeleteChar.
Constructors
Initialises the input with props and an optional state.
Instance methods
Responds to cursor-movement and editing commands.
Cmd::MoveCursorLeft— cursor − 1, clamped at 0.Cmd::MoveCursorRight— cursor + 1, clamped atprops.value.size.Cmd::InsertChar— inserts the character at the cursor, then advances cursor.Cmd::InsertString— inserts the full string at the cursor in one operation, then advances the cursor by its length. Typically built from theDataEventaCmd::Pasteproduces, so a pasted block never triggers one re-render per character.Cmd::DeleteChar— deletes the character before the cursor, then retreats cursor. ReturnsCmdResult::Nonewhen already at position 0.Cmd::SelectAll— moves the cursor toprops.value.size(full selection deferred).Cmd::MoveCursorTo— cursor set directly tocmd.position, clamped to0..props.value.size.- Any other command — returns
CmdResult::None.
Every branch that moves the cursor also re-clamps scroll_offset against the
most recently rendered frame width, if any, so state.scroll_offset stays
correct even when inspected before the next render.
Renders the input field into buf within frame.
When props.value is empty and props.placeholder is set, the placeholder
is displayed and no cursor is drawn. Otherwise, scroll_offset is adjusted
so the cursor is visible, then the value from scroll_offset onward is
rendered with props.text_style, clipped to frame.width. The character at
the cursor position is overlaid with props.cursor_style. A space is used
as the cursor glyph when the cursor is past the end of the value.
Restores state to its initial value — cursor at 0, no scroll offset.
Call this rather than replacing the instance when reusing an InputMock
for a new editing session.
Narrows the inherited state getter to InputMock::WidgetState. Safe:
initialize only ever stores a WidgetState into the base @state ivar.