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
impl AnimationDriver
Sourcepub fn add<A: Update + Send + 'static>(&mut self, anim: A) -> AnimationId
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.
Sourcepub fn tick(&mut self, dt: f32)
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.
Sourcepub fn cancel(&mut self, id: AnimationId)
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).
Sourcepub fn cancel_all(&mut self)
pub fn cancel_all(&mut self)
Cancel all active animations.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of currently active animations.
Sourcepub fn is_active(&self, id: AnimationId) -> bool
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
impl Debug for AnimationDriver
Source§impl Default for AnimationDriver
impl Default for AnimationDriver
Source§fn default() -> AnimationDriver
fn default() -> AnimationDriver
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for AnimationDriver
impl !RefUnwindSafe for AnimationDriver
impl Send for AnimationDriver
impl !Sync for AnimationDriver
impl Unpin for AnimationDriver
impl UnsafeUnpin for AnimationDriver
impl !UnwindSafe for AnimationDriver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more