class

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

new(props : Props, state : WidgetState = WidgetState.new)

Initialises the table with props and an optional state.

Source

Instance methods

handle_cmd(cmd : Cmd) : CmdResult

Responds to navigation and scroll commands.

  • Cmd::MoveDown, Cmd::ScrollDown — cursor + 1, wrapping to 0 at the end of the rows. Cmd::ScrollDown arrives from a mouse wheel via View#dispatch; it moves the cursor exactly like keyboard MoveDown.
  • Cmd::MoveUp, Cmd::ScrollUp — cursor − 1, wrapping to the last row at the top. Same relationship as the pair above.
  • Cmd::ScrollRightscroll_col + 1, unbounded (rendering simply shows no columns once scrolled past the last one).
  • Cmd::ScrollLeftscroll_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.

Source
preferred_height(width : Int32) : Int32 | Nil

The row count plus one for the header row, regardless of widthTableMock truncates overflowing columns rather than wrapping them.

Source
props
Source
props=(props : Props)
Source
render_content(frame : Frame, buf : Buffer) : Void

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.

Source
state

Narrows the inherited state getter to TableMock::WidgetState. Safe: initialize only ever stores a WidgetState into the base @state ivar.

Source

Nested types