use std::fmt::Display;
use crate::{Canvas, Layer};
pub type AnimationUpdateFunction = dyn Fn(f32, &mut Canvas, usize) -> anyhow::Result<()>;
pub type LayerAnimationUpdateFunction = dyn Fn(f32, &mut Layer, usize) -> anyhow::Result<()>;
pub struct Animation {
pub name: String,
pub update: Box<AnimationUpdateFunction>,
}
impl Animation {
pub fn new<N>(name: N, f: &'static AnimationUpdateFunction) -> Self
where
N: Display,
{
Self {
name: format!("{}", name),
update: Box::new(f),
}
}
}
impl From<(String, Box<AnimationUpdateFunction>)> for Animation {
fn from((name, f): (String, Box<AnimationUpdateFunction>)) -> Self {
Self { name, update: f }
}
}