Skip to main content

Module scroll_core

Module scroll_core 

Source
Expand description

Shared scrolling engine reused by every scrollable container.

The logic lives here as free functions so it is not triplicated across Column/Row/Container/Grid. Because ScrollState is Copy, each function takes the state by value plus a forward closure for routing a touch into the container’s children. That sidesteps the borrow checker aliasing &self.children with &self.scroll inside a container method.

Responsibilities:

  • route_touch — the tap-vs-scroll gesture decision flow.
  • render_offset — the pixel offset a container subtracts from child positions in arrange (rubber-banded while dragging, clamped otherwise).
  • snap_lines — candidate snap offsets derived from child rectangles.
  • draw_scrollbars — track + proportional thumb for both axes, honoring every ScrollbarMode.

Constants§

SCROLLBAR_W
Width/height (px) of the scrollbar gutter and thumb.

Functions§

crossed_threshold
Whether the finger has moved far enough from origin (Manhattan distance, restricted to the scrolling axes) to be treated as a scroll rather than a tap.
draw_scrollbars
Draw scrollbar tracks/thumbs after the children have been clipped+drawn. Honors all four ScrollbarModes and both axes per dir. Track color is theme.background.divider, thumb is theme.accent.base.
rect_contains
Half-open hit test: point lies within rect.
render_offset
The pixel offset a container subtracts from each child’s position during arrange. While dragging the raw offset is rubber-banded so over-scroll stretches; otherwise it is clamped to the valid range.
route_touch
Run the LVGL-style gesture flow for one touch event, returning the host message to emit (if any). forward routes a touch into the container’s children (typically the reverse child iteration) and reports whether a child consumed it.
snap_lines
Candidate snap offsets (in offset-space, i.e. valid ScrollState::offset values) derived from child_rects. origin is the viewport’s top-left, offset the scroll offset already applied to the arranged children this frame (added back so the result is independent of the current scroll), and viewport the viewport size. Returns offsets on the scrolling axis selected by dir.
thumb_rect
Thumb rectangle within track. vp/content are the relevant axis extents, offset the current scroll on that axis, vertical selects the axis. The thumb is sized to the visible fraction (minimum 8 px) and positioned by the scroll fraction.