use super::error::RendererError;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct AnimationConfig {
pub fps: u32,
pub cycle_duration: Duration,
pub infinite: bool,
pub show_progress: bool,
pub smooth: bool,
}
impl AnimationConfig {
pub fn new(fps: u32, duration: Duration) -> Self {
Self {
fps: fps.clamp(1, 144),
cycle_duration: duration,
infinite: duration.is_zero(),
show_progress: true,
smooth: false,
}
}
pub fn frame_duration(&self) -> Duration {
Duration::from_nanos(1_000_000_000u64 / self.fps as u64)
}
pub fn validate(&self) -> Result<(), RendererError> {
if !(1..=144).contains(&self.fps) {
return Err(RendererError::InvalidConfig(format!(
"FPS must be between 1 and 144, got {}",
self.fps
)));
}
if !self.infinite && self.cycle_duration.is_zero() {
return Err(RendererError::InvalidConfig(
"Non-infinite animation must have non-zero duration".to_string(),
));
}
Ok(())
}
}
impl Default for AnimationConfig {
fn default() -> Self {
Self {
fps: 30,
cycle_duration: Duration::from_secs(5),
infinite: false,
show_progress: true,
smooth: false,
}
}
}