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
Box-drawing light horizontal — the track glyph for Direction::Horizontal.
Full block — the thumb glyph.
Box-drawing light vertical — the track glyph for Direction::Vertical.
Constructors
Initialises the scrollbar with props and an optional state.
Instance methods
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.
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, setsstate.dragging = trueand returnsCmdResult::None(no position change yet, just the start of a drag). Otherwise (a track click) computes the target position and returnsCmdResult::Bubble, available via#bubbled_position.Cmd::MouseDrag— whilestate.dragging, computes and bubbles a new position exactly like a track click; returnsCmdResult::Noneif not currently dragging (a drag with no preceding thumb press).Cmd::MouseRelease— setsstate.dragging = false, returnsCmdResult::None.- Any other command — returns
CmdResult::None.
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.
Narrows the inherited state getter to ScrollbarMock::WidgetState.
Safe: initialize only ever stores a WidgetState into the base
@state ivar.