Skip to main content

AnimationDriver

Struct AnimationDriver 

Source
pub struct AnimationDriver { /* private fields */ }
Expand description

Manages a collection of animations, ticking them each frame and automatically removing completed ones.

§Example

use animato_driver::{AnimationDriver, MockClock, Clock};
use animato_tween::Tween;
use animato_core::Easing;

let mut driver = AnimationDriver::new();
let id = driver.add(
    Tween::new(0.0_f32, 1.0).duration(1.0).build()
);

assert!(driver.is_active(id));
assert_eq!(driver.active_count(), 1);

// Tick past completion:
driver.tick(2.0);
assert!(!driver.is_active(id));
assert_eq!(driver.active_count(), 0);

Implementations§

Source§

impl AnimationDriver

Source

pub fn new() -> Self

Create a new, empty driver.

Source

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

Register an animation and return its AnimationId.

The animation will be ticked on every call to tick and automatically removed when it returns false from update.

Source

pub fn tick(&mut self, dt: f32)

Advance all active animations by dt seconds.

Animations that return false from update are marked and removed at the end of the tick — no allocation during the tick itself.

Source

pub fn cancel(&mut self, id: AnimationId)

Cancel an animation by id.

The animation is removed immediately, before the next tick. No-op if the id is not found (e.g. already completed).

Source

pub fn cancel_all(&mut self)

Cancel all active animations.

Source

pub fn active_count(&self) -> usize

Number of currently active animations.

Source

pub fn is_active(&self, id: AnimationId) -> bool

true if the animation with the given id is still active.

Trait Implementations§

Source§

impl Debug for AnimationDriver

Source§

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

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

impl Default for AnimationDriver

Source§

fn default() -> AnimationDriver

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.