aboutsummaryrefslogtreecommitdiff
path: root/src/animation
diff options
context:
space:
mode:
Diffstat (limited to 'src/animation')
-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.