Phosphor::TableMock
Inherits Phosphor::MockWidget < Reference < Object
A multi-column list with a movable row cursor and horizontal column scroll.
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.
Constructors
Initialises the table with props and an optional state.
Instance methods
Responds to navigation and scroll commands.
Cmd::MoveDown,Cmd::ScrollDown— cursor + 1, wrapping to 0 at the end of the rows.Cmd::ScrollDownarrives from a mouse wheel viaView#dispatch; it moves the cursor exactly like keyboardMoveDown.Cmd::MoveUp,Cmd::ScrollUp— cursor − 1, wrapping to the last row at the top. Same relationship as the pair above.Cmd::ScrollRight—scroll_col+ 1, unbounded (rendering simply shows no columns once scrolled past the last one).Cmd::ScrollLeft—scroll_col− 1, clamped at 0.- Any other command — returns
CmdResult::None.
The row-cursor branches guard against an empty rows to avoid
division by zero.
The row count plus one for the header row, regardless of width —
TableMock truncates overflowing columns rather than wrapping them.
Renders the header row at frame.y (unless props.show_header is
false), then data rows below it, into buf within frame.
Only columns from state.scroll_col onward are drawn, left to right,
each truncated or padded to exactly column.width cells per
column.alignment; drawing stops once a column would start beyond
frame's right edge. When props.show_header is true, data rows
start at frame.y + 1 and are clipped to frame.height - 1; when
false, the header is skipped, data rows start at frame.y instead,
and clipping uses the full frame.height since no row is spent on
the header. The row at state.cursor uses props.selected_style,
all others use props.row_style — unless props.column_styles has
an entry for that row index, in which case its label_style (column
0) and value_style (every other column) take precedence over both.
Narrows the inherited state getter to TableMock::WidgetState. Safe:
initialize only ever stores a WidgetState into the base @state ivar.