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 inarrange(rubber-banded while dragging, clamped otherwise).snap_lines— candidate snap offsets derived from child rectangles.draw_scrollbars— track + proportional thumb for both axes, honoring everyScrollbarMode.
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 perdir. Track color istheme.background.divider, thumb istheme.accent.base. - rect_
contains - Half-open hit test:
pointlies withinrect. - 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).
forwardroutes 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::offsetvalues) derived fromchild_rects.originis the viewport’s top-left,offsetthe scroll offset already applied to the arranged children this frame (added back so the result is independent of the current scroll), andviewportthe viewport size. Returns offsets on the scrolling axis selected bydir. - thumb_
rect - Thumb rectangle within
track.vp/contentare the relevant axis extents,offsetthe current scroll on that axis,verticalselects the axis. The thumb is sized to the visible fraction (minimum 8 px) and positioned by the scroll fraction.