pub struct SmoothScroll {
pub offset: f32,
pub target: f32,
pub velocity: f32,
pub max: f32,
pub stiffness: f32,
pub friction: f32,
pub smooth: bool,
}Expand description
A 1-D smooth scroll axis. offset is the current (fractional) pixel offset;
target is where we’re easing toward; velocity carries momentum after a
flick. Advance with advance (injected dt) — never reads
wall-clock time.
Fields§
§offset: f32Current sub-pixel offset (what the renderer draws at).
target: f32Target offset we ease toward.
velocity: f32Current momentum (px/s).
max: f32Scrollable extent [0, max].
stiffness: f32Easing stiffness (higher = snappier). 1/seconds.
friction: f32Momentum friction per second (0..1 retained per second-ish).
smooth: boolIf false, jumps instantly to target (smooth-vs-instant toggle, SCRL-1).
Implementations§
Source§impl SmoothScroll
impl SmoothScroll
pub fn with_max(self, max: f32) -> Self
Sourcepub fn set_max(&mut self, max: f32)
pub fn set_max(&mut self, max: f32)
Set the scrollable extent (e.g. total content height − viewport height), re-clamping the target.
Sourcepub fn scroll_to(&mut self, target: f32)
pub fn scroll_to(&mut self, target: f32)
Request a scroll to an absolute offset (e.g. a scrollbar drag / key).
Sourcepub fn scroll_by(&mut self, delta: f32)
pub fn scroll_by(&mut self, delta: f32)
Scroll by a delta (wheel/keys). Adds momentum proportional to the delta so repeated flicks accelerate (SCRL-1).
Sourcepub fn flick(&mut self, velocity: f32)
pub fn flick(&mut self, velocity: f32)
Apply a momentum flick (px/s), e.g. from a fast drag release.
Sourcepub fn advance(&mut self, dt: f32)
pub fn advance(&mut self, dt: f32)
Advance the animation by dt seconds (the injected clock). Integrates
momentum + eases the offset toward the target with a critically-ish damped
spring. Deterministic: same state + dt → same result.
Sourcepub fn animating(&self) -> bool
pub fn animating(&self) -> bool
Whether the animation is still moving (caller requests a repaint while so).
Sourcepub fn first_row_and_frac(&self, row_h: f32) -> (usize, f32)
pub fn first_row_and_frac(&self, row_h: f32) -> (usize, f32)
The integer row index at the current offset given a uniform row height, and the fractional pixel remainder the renderer draws at (SCRL-2: render at a fractional offset + clip).
Trait Implementations§
Source§impl Clone for SmoothScroll
impl Clone for SmoothScroll
Source§fn clone(&self) -> SmoothScroll
fn clone(&self) -> SmoothScroll
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SmoothScroll
Source§impl Debug for SmoothScroll
impl Debug for SmoothScroll
Source§impl Default for SmoothScroll
impl Default for SmoothScroll
Source§impl<'de> Deserialize<'de> for SmoothScroll
impl<'de> Deserialize<'de> for SmoothScroll
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SmoothScroll
impl PartialEq for SmoothScroll
Source§fn eq(&self, other: &SmoothScroll) -> bool
fn eq(&self, other: &SmoothScroll) -> bool
self and other values to be equal, and is used by ==.