Skip to main content

ScrollDriver

Struct ScrollDriver 

Source
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

Source

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.

Source

pub fn add<A: Update + Send + 'static>(&mut self, animation: A)

Register an animation to be driven by scroll changes.

Source

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.

Source

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.

Source

pub fn position(&self) -> f32

Current scroll position in user units.

Source

pub fn progress(&self) -> f32

Normalised scroll progress ∈ [0.0, 1.0].

Source

pub fn min(&self) -> f32

Minimum position of the scroll range.

Source

pub fn max(&self) -> f32

Maximum position of the scroll range.

Source

pub fn animation_count(&self) -> usize

Number of registered animations.

Trait Implementations§

Source§

impl Debug for ScrollDriver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ScrollDriver

Source§

fn default() -> ScrollDriver

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.