Expand description
LVGL-style scroll state + math, living next to layout.
Widgets in zest are transient: the Runtime
rebuilds the whole tree from view(&self) every frame, so a container
cannot itself remember a drag origin or a fling velocity. All cross-frame
scroll/gesture state therefore lives in a single host-owned value —
ScrollState — which the screen stores as a field and passes by
reference into view. Containers only read it during measure/arrange/
draw and emit ScrollMsg in handle_touch; the owned copy is mutated
only in update() via ScrollState::apply and ScrollState::tick.
Touch events carry no timestamp (see event), so velocity
for fling is sampled in update() from embassy_time::Instant deltas the
caller passes as now_ms, never inside handle_touch. Momentum is driven
by a self-rescheduling tick_task (a 16 ms Timer-delayed Task),
not a subscription, so the animation cleanly stops when it settles.
The math deliberately avoids libm: the tap-vs-scroll threshold uses
Manhattan distance, and friction is a per-frame-constant multiply (no
powf/sqrt), valid because the tick dt is approximately constant at
16 ms.
Structs§
- Scroll
State - Cross-frame scroll/gesture/velocity state owned by the host screen.
Enums§
- Gesture
Phase - Gesture / animation phase of a
ScrollState. - Scroll
Direction - Which axes a container scrolls on.
- Scroll
Msg - Message a scrollable container emits in
handle_touch; the host applies it inupdate(). Carries the geometry (and snap lines on release) so the ownedScrollStatecan integrate without touching layout. - Scrollbar
Mode - When the scrollbar thumb is visible.
- Snap
Mode - How scrolling settles to content boundaries.
Constants§
- FRICTION
- Velocity multiplier applied each animation frame during a fling.
- MAX_
FLING_ V - Maximum fling speed (px/s, per axis) the release sample is capped to.
- MIN_
FLING_ V - Minimum fling speed (px/s, per axis) below which a fling becomes a spring.
- RUBBER_
C - Rubber-band resistance coefficient: larger → stiffer over-scroll.
- SCROLL_
THRESHOLD - Pixel distance a finger must travel before a press is reinterpreted as a
scroll (Manhattan distance,
|dx| + |dy|). - SPRING_
K - Spring stiffness: fraction of the remaining distance closed each frame.
- TICK_MS
- Animation frame period in milliseconds (~60 fps).
Functions§
- tick_
task - Self-rescheduling animation clock: a
Taskthat waits one frame (~16 ms) and then yieldsmsg, so the host’sScrollTickarm can callScrollState::tickand re-arm whileScrollState::is_animating.