dioxus_motion/
animation.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
pub use instant::Duration;

use crate::spring::Spring;

use easer::functions::{Easing, Linear};

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Tween {
    pub duration: Duration,
    pub easing: fn(f32, f32, f32, f32) -> f32,
}

impl Default for Tween {
    fn default() -> Self {
        Self {
            duration: Duration::from_millis(300),
            easing: Linear::ease_in_out,
        }
    }
}

impl Tween {
    pub fn new(duration: Duration) -> Self {
        Self {
            duration,
            easing: Linear::ease_in_out,
        }
    }

    pub fn with_easing(mut self, easing: fn(f32, f32, f32, f32) -> f32) -> Self {
        self.easing = easing;
        self
    }
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AnimationMode {
    Tween(Tween),
    Spring(Spring),
}

impl Default for AnimationMode {
    fn default() -> Self {
        Self::Tween(Tween::default())
    }
}

/// Represents the current state of an animation
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AnimationState {
    Idle,
    Running,
    Completed,
}