| 1 |
mod scroll;
|
| 2 |
|
| 3 |
pub use scroll::ScrollAnimation;
|
| 4 |
|
| 5 |
use std::time::Duration;
|
| 6 |
|
| 7 |
#[derive(Debug, Clone, Copy)]
|
| 8 |
pub enum Easing {
|
| 9 |
Linear,
|
| 10 |
EaseOut,
|
| 11 |
EaseInOut,
|
| 12 |
}
|
| 13 |
|
| 14 |
impl Easing {
|
| 15 |
pub fn apply(&self, t: f64) -> f64 {
|
| 16 |
match self {
|
| 17 |
Easing::Linear => t,
|
| 18 |
Easing::EaseOut => 1.0 - (1.0 - t).powi(3),
|
| 19 |
Easing::EaseInOut => {
|
| 20 |
if t < 0.5 {
|
| 21 |
4.0 * t * t * t
|
| 22 |
} else {
|
| 23 |
1.0 - (-2.0 * t + 2.0).powi(3) / 2.0
|
| 24 |
}
|
| 25 |
}
|
| 26 |
}
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
| 30 |
pub struct AnimationConfig {
|
| 31 |
pub duration: Duration,
|
| 32 |
pub easing: Easing,
|
| 33 |
}
|
| 34 |
|
| 35 |
impl Default for AnimationConfig {
|
| 36 |
fn default() -> Self {
|
| 37 |
Self {
|
| 38 |
duration: Duration::from_millis(150),
|
| 39 |
easing: Easing::EaseOut,
|
| 40 |
}
|
| 41 |
}
|
| 42 |
}
|