pub trait Playable: Update + Any {
// Required methods
fn duration(&self) -> f32;
fn reset(&mut self);
fn seek_to(&mut self, progress: f32);
fn is_complete(&self) -> bool;
fn as_any(&self) -> &(dyn Any + 'static);
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static);
}Expand description
Object-safe animation interface used by composition containers.
Update is intentionally tiny: it only advances an animation. Playable
adds the small amount of control a timeline needs to reset and seek children
without knowing their concrete type.
Implementations should interpret seek_to as normalized
progress through their finite duration, clamped to [0.0, 1.0].
§Example
use animato_core::{Playable, Update};
#[derive(Default)]
struct Clip { elapsed: f32 }
impl Update for Clip {
fn update(&mut self, dt: f32) -> bool {
self.elapsed = (self.elapsed + dt.max(0.0)).min(1.0);
!self.is_complete()
}
}
impl Playable for Clip {
fn duration(&self) -> f32 { 1.0 }
fn reset(&mut self) { self.elapsed = 0.0; }
fn seek_to(&mut self, progress: f32) {
self.elapsed = progress.clamp(0.0, 1.0);
}
fn is_complete(&self) -> bool { self.elapsed >= 1.0 }
fn as_any(&self) -> &dyn core::any::Any { self }
fn as_any_mut(&mut self) -> &mut dyn core::any::Any { self }
}Required Methods§
Sourcefn is_complete(&self) -> bool
fn is_complete(&self) -> bool
true when the animation has reached its terminal state.
Sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Return a type-erased shared reference for downcasting.
Sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Return a type-erased mutable reference for downcasting.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".