#[cfg(feature = "nostd")]
use alloc::{string::String, vec::Vec};
#[cfg(not(feature = "nostd"))]
use std::{string::String, vec::Vec};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnimationInterpolation {
Linear,
Smooth,
Smoother,
}
#[derive(Debug, Clone)]
pub struct AnimationTag {
pub t1: Option<u32>,
pub t2: Option<u32>,
pub accel: Option<f32>,
pub modifiers: Vec<String>,
}
pub type InterpolationFn = fn(f32) -> f32;
#[derive(Debug, Clone)]
pub struct AnimationTiming {
pub start_cs: u32,
pub end_cs: u32,
pub accel: f32,
}
impl AnimationTiming {
pub fn new(start_cs: u32, end_cs: u32, accel: f32) -> Self {
Self {
start_cs,
end_cs,
accel,
}
}
pub fn progress(&self, time_cs: u32) -> f32 {
if time_cs <= self.start_cs {
return 0.0;
}
if time_cs >= self.end_cs {
return 1.0;
}
let duration = (self.end_cs - self.start_cs) as f32;
let elapsed = (time_cs - self.start_cs) as f32;
let linear_progress = elapsed / duration;
if (self.accel - 1.0).abs() < 0.001 {
linear_progress
} else {
linear_progress.powf(self.accel)
}
}
}