pub struct ScrollDriver { /* private fields */ }Expand description
Drives registered animations from a normalised scroll position.
Each call to set_position advances every
animation by Δposition / range — a normalised fraction ∈ [0, 1].
§Example
use animato_driver::scroll::ScrollDriver;
use animato_core::Update;
struct Counter(u32);
impl Update for Counter {
fn update(&mut self, _dt: f32) -> bool { self.0 += 1; self.0 < 10 }
}
let mut driver = ScrollDriver::new(0.0, 1000.0);
driver.add(Counter(0));
driver.set_position(250.0); // 25% through the scroll range
driver.set_position(500.0); // another 25%Implementations§
Source§impl ScrollDriver
impl ScrollDriver
Sourcepub fn new(min: f32, max: f32) -> Self
pub fn new(min: f32, max: f32) -> Self
Create a scroll driver over the given position range.
min and max define the full scroll extent. max is clamped to be
strictly greater than min.
Sourcepub fn add<A: Update + Send + 'static>(&mut self, animation: A)
pub fn add<A: Update + Send + 'static>(&mut self, animation: A)
Register an animation to be driven by scroll changes.
Sourcepub fn set_position(&mut self, pos: f32)
pub fn set_position(&mut self, pos: f32)
Update the scroll position and tick all animations by the normalised delta.
If pos is outside [min, max] it is clamped. Animations receive a
dt equal to |Δpos| / (max − min), i.e. a normalised [0, 1] delta.
Completed animations (returning false) are retained so they stay at
their terminal value — call clear_completed
if you want to remove them.
Sourcepub fn clear_completed(&mut self)
pub fn clear_completed(&mut self)
Remove all animations that have returned false from their last update.
This is not done automatically, so completed animations stay accessible for value reads after they finish.
Sourcepub fn animation_count(&self) -> usize
pub fn animation_count(&self) -> usize
Number of registered animations.