class

Phosphor::ScrollbarMock

Inherits Phosphor::MockWidget < Reference < Object

A scroll position indicator rendered along one edge of a frame.

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. Pair it with ListMock, TableMock, or ViewportMock, which own the actual scroll position, and pass their state.scroll/scroll_row/scroll_offset through as Props#position.

Handles click-to-position and drag via Cmd::MousePress/ Cmd::MouseDrag/Cmd::MouseRelease, but never mutates props.position itself — position is driven from Props, same as everything else here. Instead, handle_cmd computes the target position and returns CmdResult::Bubble; since CmdResult is a plain enum (no payload, matching every other MockWidget#handle_cmd contract), the computed value is exposed separately via #bubbled_position, which the owning Widget reads immediately after the bubbling call to learn what to do with it.

Constants

HORIZONTAL_TRACK_CHAR = "─"

Box-drawing light horizontal — the track glyph for Direction::Horizontal.

THUMB_CHAR = "█"

Full block — the thumb glyph.

VERTICAL_TRACK_CHAR = "│"

Box-drawing light vertical — the track glyph for Direction::Vertical.

Constructors

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

Initialises the scrollbar with props and an optional state.

Source

Instance methods

bubbled_position

The position most recently computed by a bubbling Cmd::MousePress or Cmd::MouseDrag — read this immediately after such a call to learn what handle_cmd computed; see the class doc comment for why this exists instead of a payload on CmdResult::Bubble. nil until the first click/drag bubbles.

Source
handle_cmd(cmd : Cmd) : CmdResult

Responds to mouse commands. ScrollbarMock never mutates its own scroll position — the widget that owns the scroll (e.g. ListMock) does, driven by whatever this bubbles up.

  • Cmd::MousePress — if (x, y) lands on the thumb, sets state.dragging = true and returns CmdResult::None (no position change yet, just the start of a drag). Otherwise (a track click) computes the target position and returns CmdResult::Bubble, available via #bubbled_position.
  • Cmd::MouseDrag — while state.dragging, computes and bubbles a new position exactly like a track click; returns CmdResult::None if not currently dragging (a drag with no preceding thumb press).
  • Cmd::MouseRelease — sets state.dragging = false, returns CmdResult::None.
  • Any other command — returns CmdResult::None.
Source
props
Source
props=(props : Props)
Source
render_content(frame : Frame, buf : Buffer) : Void

Renders the track and thumb into buf within frame.

Direction::Vertical renders a single column along frame's right edge, frame.height cells long; Direction::Horizontal renders a single row along frame's bottom edge, frame.width cells long. Thumb size and position are computed from props.total, props.visible, and props.position against that track length. Track cells use props.style; thumb cells use props.thumb_style.

Source
state

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

Source

Nested types