diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-07 11:32:02 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-07 13:16:54 +0400 |
| commit | f9085db5648bc6bad7fb0abf45e2a11f2e03d1af (patch) | |
| tree | 56b32abe55f9857649f0296a0e36c30cd20c38e5 /src/animation.rs | |
| parent | 49ce791d13031ba5396b2ee8dbbffe128d64ff0f (diff) | |
| download | niri-f9085db5648bc6bad7fb0abf45e2a11f2e03d1af.tar.gz niri-f9085db5648bc6bad7fb0abf45e2a11f2e03d1af.tar.bz2 niri-f9085db5648bc6bad7fb0abf45e2a11f2e03d1af.zip | |
Implement window open animations
Diffstat (limited to 'src/animation.rs')
| -rw-r--r-- | src/animation.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/animation.rs b/src/animation.rs index addfdfca..bf0536e2 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -15,6 +15,13 @@ pub struct Animation { duration: Duration, start_time: Duration, current_time: Duration, + curve: Curve, +} + +#[derive(Debug, Clone, Copy)] +pub enum Curve { + EaseOutCubic, + EaseOutExpo, } impl Animation { @@ -29,9 +36,15 @@ impl Animation { duration: over.mul_f64(ANIMATION_SLOWDOWN.load(Ordering::Relaxed)), start_time: now, current_time: now, + curve: Curve::EaseOutCubic, } } + pub fn with_curve(mut self, curve: Curve) -> Self { + self.curve = curve; + self + } + pub fn set_current_time(&mut self, time: Duration) { self.current_time = time; } @@ -44,7 +57,7 @@ impl Animation { let passed = (self.current_time - self.start_time).as_secs_f64(); let total = self.duration.as_secs_f64(); let x = (passed / total).clamp(0., 1.); - EaseOutCubic.y(x) * (self.to - self.from) + self.from + self.curve.y(x) * (self.to - self.from) + self.from } pub fn to(&self) -> f64 { @@ -56,3 +69,12 @@ impl Animation { self.from } } + +impl Curve { + pub fn y(self, x: f64) -> f64 { + match self { + Curve::EaseOutCubic => EaseOutCubic.y(x), + Curve::EaseOutExpo => 1. - 2f64.powf(-10. * x), + } + } +} |
