Skip to main content

Module scrollbar

Module scrollbar 

Source
Expand description

Optional vertical scrollbar helpers, gated behind the scrollbar feature.

Two pieces, both pure and panel-agnostic (they work for a MultiSelectPanel, a SelectablePanel, or any home-grown scrollable content):

  • scroll_for_track_row maps a clicked/dragged terminal row within a scrollbar track to a scroll offset, so a click or drag anywhere in the track jumps/scrolls proportionally — the way a native scrollbar behaves.
  • render_scrollbar draws a ratatui Scrollbar into a track column, sizing and positioning the thumb from total/capacity/start and no-op-ing when everything already fits.

Panels that own their scroll offset (MultiSelectPanel) expose thin convenience wrappers ([MultiSelectPanel::scroll_to_track_row] and [MultiSelectPanel::render_scrollbar]) that plumb their own geometry into these functions; callers that keep scroll externally can use the free functions directly.

Structs§

ScrollbarStyle
Visual styling for render_scrollbar. Start from ScrollbarStyle::default (a right-hand vertical bar with a track and a solid thumb, both unstyled) and override what you want — most callers only set track_style/thumb_style to their theme’s dim/accent colours.

Functions§

render_scrollbar
Render a vertical scrollbar into area, sizing the thumb from total content rows, the visible capacity (rows that fit at once) and the current start scroll offset. A no-op when the area is empty or the content already fits (total <= capacity), so callers can call it unconditionally.
scroll_for_track_row
Map a clicked/dragged terminal row within a vertical scrollbar track to a scroll offset in 0..=max_scroll, clamped to the track’s own bounds (so a click above the track reads as the top and below it as the bottom). Returns 0 when there’s nothing to scroll (an empty track or max_scroll == 0).