pub struct AnimationController { /* private fields */ }Expand description
A 0.0..=1.0 value driven by a duration + Curve or a Spring fling.
Plain data + math (see the module contract): a widget advances it during
paint and re-requests a frame while advance returns true.
forward/reverse/animate_to settle as Completed/Dismissed; repeat
never completes; a fling settles at 1.0 (non-negative velocity) or 0.0.
§Overshoot (spring-driven only)
A fling is not clamped in flight: an under-damped SpringDesc (M3’s spatial
presets use damping_ratio: 0.9) overshoots on purpose, then lands exactly on
the target. Use value_clamped for a bounded read.
Implementations§
Source§impl AnimationController
impl AnimationController
Sourcepub fn new(duration: Duration) -> Self
pub fn new(duration: Duration) -> Self
Create an idle controller at 0.0 with the given default duration and Curve::Linear.
Sourcepub fn with_curve(self, curve: Curve) -> Self
pub fn with_curve(self, curve: Curve) -> Self
Set the easing curve applied to duration-driven motion (builder-style).
Sourcepub fn value(&self) -> f64
pub fn value(&self) -> f64
The current value: within 0.0..=1.0 for duration motion, but a spring
fling may transiently leave that range (see the type docs’
Overshoot section); see value_clamped.
Sourcepub fn value_clamped(&self) -> f64
pub fn value_clamped(&self) -> f64
value clamped to 0.0..=1.0; differs from it only while a
fling overshoots.
Sourcepub fn status(&self) -> AnimationStatus
pub fn status(&self) -> AnimationStatus
The current lifecycle status.
Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Whether a motion is in progress (the next advance makes progress).
Sourcepub fn animate_to(&mut self, target: f64)
pub fn animate_to(&mut self, target: f64)
Animate from the current value to target (clamped to 0.0..=1.0) over
the controller’s duration.
Sourcepub fn repeat(&mut self)
pub fn repeat(&mut self)
Loop 0.0→1.0 (eased) indefinitely with a period of the controller’s
duration. advance always returns true for a repeat.
Sourcepub fn fling(&mut self, velocity: f64, spring: SpringDesc)
pub fn fling(&mut self, velocity: f64, spring: SpringDesc)
Start a spring fling from the current value with initial velocity (value
units per second), settling at 1.0 for a non-negative velocity, else 0.0.
The value is not clamped in flight (see the type docs’ Overshoot section).
Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Halt any in-progress motion, leaving the value where it is and the status
AnimationStatus::Idle.
Sourcepub fn advance(&mut self, now: FrameTime) -> bool
pub fn advance(&mut self, now: FrameTime) -> bool
Advance to frame time now, returning whether it is still animating (the
caller must then request another frame).
The delta uses FrameTime::saturating_sub, so a repeated or out-of-order
timestamp yields a zero delta, never a panic or NaN. The first advance
after starting a motion only seeds the clock.