use std::time::Duration;
use super::easing::EasingFn;
use super::easing::ease_out_quad;
#[derive(Debug, Clone)]
pub struct AnimationConfig {
pub duration: Duration,
pub easing: EasingFn,
pub delay: Duration,
pub repeat: bool,
pub reverse: bool,
}
impl Default for AnimationConfig {
fn default() -> Self {
Self {
duration: Duration::from_millis(200),
easing: ease_out_quad,
delay: Duration::ZERO,
repeat: false,
reverse: false,
}
}
}
impl AnimationConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_duration(mut self, duration: Duration) -> Self {
self.duration = duration;
self
}
pub fn with_easing(mut self, easing: EasingFn) -> Self {
self.easing = easing;
self
}
pub fn with_delay(mut self, delay: Duration) -> Self {
self.delay = delay;
self
}
pub fn with_repeat(mut self) -> Self {
self.repeat = true;
self
}
pub fn with_reverse(mut self) -> Self {
self.reverse = true;
self
}
pub fn to_gpui_animation(self) -> gpui::Animation {
let mut animation = gpui::Animation::new(self.duration);
if self.repeat {
animation = animation.repeat();
}
animation
}
}
#[derive(Debug, Clone, Default)]
pub struct AnimationState {
pub progress: f32,
pub is_running: bool,
pub is_paused: bool,
}
impl AnimationState {
pub fn new() -> Self {
Self {
progress: 0.0,
is_running: false,
is_paused: false,
}
}
pub fn reset(&mut self) {
self.progress = 0.0;
self.is_running = false;
self.is_paused = false;
}
pub fn update(&mut self, progress: f32) {
self.progress = progress.clamp(0.0, 1.0);
}
}