pub struct ScrollState { /* private fields */ }Expand description
Scroll state for smooth, momentum-based scrolling with rubber-banding.
Keeps track of the current fractional scroll offset, velocity, and drag-to-scroll gestures. Completely separate from drawing, and generic over time: takes a time delta step to decay velocity or animate snap-back, making it deterministic and suitable for unit tests.
Implementations§
Source§impl ScrollState
impl ScrollState
Sourcepub const fn with_physics(physics: ScrollPhysics) -> Self
pub const fn with_physics(physics: ScrollPhysics) -> Self
Create a new ScrollState with custom physics.
Sourcepub const fn set_offset(&mut self, offset: f32, max_offset: f32)
pub const fn set_offset(&mut self, offset: f32, max_offset: f32)
Set the offset directly, clamping it to bounds.
Sourcepub fn integer_offset(&self) -> usize
pub fn integer_offset(&self) -> usize
Returns the integer part of the offset, clamped to positive.
Sourcepub fn fractional_offset(&self) -> f32
pub fn fractional_offset(&self) -> f32
Returns the fractional remainder of the offset (0.0..1.0).
Sourcepub fn tick(&mut self, dt: Duration, max_offset: f32)
pub fn tick(&mut self, dt: Duration, max_offset: f32)
Update physics for a single frame step.
Decays momentum if in bounds, or animates the rubber-band spring back to boundaries if out of bounds. Has no effect if dragging is active.
Sourcepub const fn begin_drag(&mut self, y: f32)
pub const fn begin_drag(&mut self, y: f32)
Begin a drag gesture at pointer coordinate y.
Sourcepub fn update_drag(&mut self, y: f32, max_offset: f32)
pub fn update_drag(&mut self, y: f32, max_offset: f32)
Update the drag gesture with a new pointer coordinate y.
Sourcepub fn end_drag(&mut self)
pub fn end_drag(&mut self)
End the current drag gesture, initiating a fling if pointer speed was sufficient.
Sourcepub fn scroll_by_wheel(&mut self, delta: f32)
pub fn scroll_by_wheel(&mut self, delta: f32)
Apply a scroll wheel impulse directly to velocity.
Trait Implementations§
Source§impl Clone for ScrollState
impl Clone for ScrollState
Source§fn clone(&self) -> ScrollState
fn clone(&self) -> ScrollState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more