Skip to main content

Module scroll_bar

Module scroll_bar 

Source
Expand description

ScrollBar — pointer and keyboard affordance for a ScrollArea.

ScrollBar reads and writes a shared Signal<f32> scroll position and a Signal<f32> viewport/content ratio, both supplied by its owning ScrollArea. Interaction (thumb drag, track click, keyboard Up/Down/Home/End, hover) is handled here; all painting is delegated to the active [ScrollBarStyle] impl so the look is fully theme-overridable.

Most applications do not need to construct a ScrollBar directly — ScrollArea creates and manages the bars automatically. Use this type when building a custom scroll host (e.g. the RichTextEditor manages its own bars to avoid the wrap/scrollbar circular dependency).

§Reaching the thumb with a finger

The bar is 8–12 dp wide, and it stays that way at every density: growing it would move the content beside it, and a scroll bar is chrome. The thumb is reached instead by the two mechanisms built for exactly this — the node widens for a coarse pointer through [Widget::hit_outset], to the 48 dp Android reserves for a scrollbar touch target, and the thumb itself is published through [Widget::target_regions] so the target-conformance audit can see a rectangle that is painted inside one leaf node and would otherwise be invisible to it. A precise pointer gets no outset at all: a cursor’s hot-spot is exact, and widening its targets steals clicks from the content.

Because the outset widens the bar across the scroll axis, every decision about whether a press is on the thumb is taken along the axis only — a finger 15 dp inboard of an 8 dp bar is beside the thumb, not past it.

The minimum thumb length is the active style’s [ScrollBarStyle::min_thumb_length], which follows the density (24 dp Compact, 44 dp Touch under the shipped style), so a short thumb on a long document is still something a finger can land on.

§Accessibility

Hidden from AT via set_hidden(). Scroll actions (Up/Down/Left/Right) are advertised on the parent ScrollView node, not on the bar, so screen readers navigate the content region directly without stopping on the thumb.

let position = Signal::new(0.0_f32);
let max_scroll = Signal::new(500.0_f32);
let viewport_ratio = Signal::new(0.4_f32);
let _bar = ScrollBar::new(
    ScrollBarOrientation::Vertical,
    position,
    max_scroll,
    viewport_ratio,
)
.thickness(8.0)
.variant(ScrollBarVariant::Overlay);

Structs§

ScrollBar
A scroll bar that shares reactive scroll-position state with a ScrollArea.

Enums§

ScrollBarOrientation
ScrollBarVariant
ScrollBarVisual

Constants§

SCROLLBAR_COARSE_TARGET
The width a scroll bar’s thumb must be reachable across for a finger.
SCROLLBAR_MIN_THUMB_LENGTH
The shipped minimum thumb length, at Compact.
SCROLLBAR_PART_THUMB
Which part of the bar a [TargetRegion] describes.
SCROLLBAR_PART_TRACK
The track either side of the thumb: a tap there pages.