aboutsummaryrefslogtreecommitdiff
path: root/src/animation/mod.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-04-17 11:00:24 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-04-17 11:31:34 +0300
commit37840a418aeba33cfba196d2ce7dd7227369dd85 (patch)
treededea6d6fe9008808799a8bd3ecf459363b02a47 /src/animation/mod.rs
parent4a4c972ffb900951b65fb5317b62c592bbccfc44 (diff)
downloadniri-37840a418aeba33cfba196d2ce7dd7227369dd85.tar.gz
niri-37840a418aeba33cfba196d2ce7dd7227369dd85.tar.bz2
niri-37840a418aeba33cfba196d2ce7dd7227369dd85.zip
animation: Extract value_at() and fix animations off difference
Diffstat (limited to 'src/animation/mod.rs')
-rw-r--r--src/animation/mod.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/animation/mod.rs b/src/animation/mod.rs
index b2f26b32..044ddd46 100644
--- a/src/animation/mod.rs
+++ b/src/animation/mod.rs
@@ -242,12 +242,21 @@ impl Animation {
self.clock.now() >= self.start_time + self.clamped_duration
}
- pub fn value(&self) -> f64 {
- if self.is_done() {
+ pub fn value_at(&self, at: Duration) -> f64 {
+ if at <= self.start_time {
+ // Return from when at == start_time so that when the animations are off, the behavior
+ // within a single event loop cycle (i.e. no time had passed since the start of an
+ // animation) matches the behavior when the animations are on.
+ return self.from;
+ } else if self.start_time + self.duration <= at {
+ return self.to;
+ }
+
+ if self.clock.should_complete_instantly() {
return self.to;
}
- let passed = self.clock.now().saturating_sub(self.start_time);
+ let passed = at.saturating_sub(self.start_time);
match self.kind {
Kind::Easing { curve } => {
@@ -280,6 +289,10 @@ impl Animation {
}
}
+ pub fn value(&self) -> f64 {
+ self.value_at(self.clock.now())
+ }
+
/// Returns a value that stops at the target value after first reaching it.
///
/// Best effort; not always exactly precise.