pub struct AnimationController { /* private fields */ }Expand description
The animation vocabulary: the shell-fed frame clock (FrameTime)
plus the pure easing/interpolation/spring math a widget or app advances it
through, flat-re-exported from frust-core::anim. Time enters from the
shell during paint (PaintCtx::frame_time); nothing here reads a clock.
A 0.0..=1.0 animation value driven either by a duration + Curve or by
a Spring fling.
It is plain data + math (see the module docs’ contract): it holds no
clock and no scheduler. A widget advances it during paint with the frame’s
FrameTime, reads value, and re-requests a frame while
advance keeps returning true.
§Status semantics
forward/reverse drive to the 1.0/
0.0 bounds and settle as Completed/Dismissed. animate_to
settles as Completed when it moved forward (target ≥ start) and Dismissed
when it moved reverse. repeat never completes (advance
always returns true). A fling settles at 1.0 (positive
velocity) or 0.0 (negative) as Completed/Dismissed.
§Overshoot (spring-driven only)
Duration+Curve motion (forward/reverse/animate_to/repeat)
always keeps value in 0.0..=1.0 — unchanged from before
this contract existed. A fling, by contrast, is not
clamped while in flight: an under-damped SpringDesc (M3’s spatial
presets use damping_ratio: 0.9) genuinely overshoots its target before
settling, and that overshoot is the whole visual point of a “bouncy”
spring — clamping it away would hide it. value() may therefore transiently
read outside [0, 1] mid-fling; it always lands exactly on the target
(0.0/1.0) once advance reports settled (status()
becomes Completed/Dismissed). A consumer that needs the value
pinned to [0, 1] at every frame (e.g. to feed a Lerp/Tween that
assumes bounded input) should use value_clamped
instead. A critically-/over-damped spring (damping_ratio >= 1.0, e.g.
M3’s “effects” presets) released with zero velocity (the common
“settle to target” fling usage) never overshoots in the first place, so
value()/value_clamped() agree for that case; a large enough release
velocity can still carry even a critically-/over-damped spring past its
target before it settles back — damping ratio bounds oscillation
(repeated overshoot), not a single one.
Implementations§
Source§impl AnimationController
impl AnimationController
Sourcepub fn new(duration: Duration) -> AnimationController
pub fn new(duration: Duration) -> AnimationController
Create an idle controller at value 0.0 with the given default duration
and a Curve::Linear easing.
Sourcepub fn with_curve(self, curve: Curve) -> AnimationController
pub fn with_curve(self, curve: Curve) -> AnimationController
Set the easing curve applied to duration-driven motion (returns self
for builder-style construction).
Sourcepub fn value(&self) -> f64
pub fn value(&self) -> f64
The current value.
For duration+Curve motion this is always in 0.0..=1.0. For a
spring fling it may transiently read outside that
range — an under-damped spring’s overshoot is real motion, not a bug
(see the type docs’ Overshoot section) — but always lands exactly on
the target once the fling settles. Use
value_clamped if a bounded [0, 1] read is
required instead.
Sourcepub fn value_clamped(&self) -> f64
pub fn value_clamped(&self) -> f64
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 currently in progress (the next advance
will make 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 (in
value-units per second). It settles toward 1.0 for a non-negative
velocity, 0.0 otherwise.
Unlike duration+Curve motion, the value driven by a fling is
not clamped to [0, 1] while in flight — see the type docs’
Overshoot section and value/
value_clamped.
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 the animation to frame time now, returning whether it is still
animating (in which case the caller must request another frame).
The delta from the previous advance is derived via
FrameTime::saturating_sub, so a repeated or out-of-order timestamp
yields a zero (never negative) delta: safe, no panic, no NaN. The first
advance after starting a motion only seeds the clock (zero delta); the
next one makes progress.
Trait Implementations§
Source§impl Clone for AnimationController
impl Clone for AnimationController
Source§fn clone(&self) -> AnimationController
fn clone(&self) -> AnimationController
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for AnimationController
Auto Trait Implementations§
impl Freeze for AnimationController
impl RefUnwindSafe for AnimationController
impl Send for AnimationController
impl Sync for AnimationController
impl Unpin for AnimationController
impl UnsafeUnpin for AnimationController
impl UnwindSafe for AnimationController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.