Skip to main content

Module scrollbar

Module scrollbar 

Expand description

Shared scrollbar interaction model — the single source of truth for thumb geometry, thumb dragging, and track paging used by every scroll-capable widget in the toolkit (Scrollable, DataTable, DocumentViewport).

Each widget owns its own track geometry (bars live on different edges/insets) and its own authoritative offset; this module turns a (track, metrics, cursor) triple into a thumb rect, a drag delta, or a page step so the behaviour stays byte-for-byte identical everywhere — pressing the thumb anchors (cursor, offset) and a subsequent move maps the cursor delta onto the content range (clamped to [0, max_scroll]); pressing the track pages the view by PAGE_FRACTION of a viewport; hover reports whether the pointer is over the thumb so the owner can brighten it.

The model holds only ephemeral interaction state (a drag anchor + hover flag) and is deliberately axis-scoped: a widget that scrolls on both axes owns two Scrollbars.

Structs§

BarFade
The idle fade of an overlay scroll bar: fully visible for a moment after scrolling, then fading out, unless something holds it (the pointer near the bar, a drag, keyboard focus, reduced motion, an always-visible bar). One timer for Scrollable and painted super::ScrollRegions, so every bar in the system appears and fades alike.
PrimaryScrollRegion
The application’s explicit primary region. Owners stamp component identity.
ScrollMetrics
The scroll geometry along one axis, all lengths in logical px.
Scrollbar
A single-axis scrollbar interaction model.
TrackMark
One annotation along a scroll track: where a search hit, a change or a diagnostic sits in the content, painted as a short mark across the track so the person sees where to scroll.

Enums§

PressOutcome
Outcome of a press hit-tested against one bar.
PrimaryScrollAction
PrimaryScrollResult

Constants§

FIT_EPS
Content must exceed the viewport by more than this (logical px) on an axis before it is considered scrollable — otherwise the content “fits” and the bar should be hidden entirely.
MIN_THUMB_LEN
Minimum thumb length (logical px) so a near-infinite content still leaves a grabbable target.
PAGE_FRACTION
Fraction of a viewport scrolled when paging via a track click.
TRACK_ALPHA
Alpha of the track behind a pinned or expanded bar — the faintest derived tier, so the track reads as a groove and not a second thumb.

Functions§

horizontal_track
vertical_track across the bottom edge of rect.
thumb_color
The thumb’s fill: the secondary ink while hovered, dragged or focused, stepped out until it clears the non-text floor (3:1) against the ground it scrolls over. At rest it is the quiet tertiary ink on a dark ground; on a light ground the same ink reads as a heavy dark bar, so it rests a third of the way back toward the ground (it still clears the floor once the pointer is on it). One answer for every scroll owner.
track_color
The track’s fill behind an expanded bar, derived against the base surface.
vertical_track
The track of a vertical bar along the trailing edge of rect, centred in the gutter column (metrics.scrollbar_gutter) a scroll owner keeps free for it: two thirds of the gutter thick, a sixth of it clear on each side and at both ends.