Skip to main content

Animation

Trait Animation 

Source
pub trait Animation<T>: 'static
where T: Animatable,
{
Show 15 methods // Required methods fn value(&self) -> &T; fn state(&self) -> AnimationState; fn tick(&mut self, delta: Duration); fn pause(&mut self); fn resume(&mut self); fn cancel(&mut self); fn seek(&mut self, progress: f32); fn finish(&mut self); // Provided methods fn duration(&self) -> Option<Duration> { ... } fn advance(&mut self, delta: Duration) -> Duration { ... } fn retarget(&mut self, _target: &T) -> bool { ... } fn is_active(&self) -> bool { ... } fn set_rate(&mut self, _rate: f64) { ... } fn rate(self, rate: f64) -> Self where Self: Sized { ... } fn into_value(self: Box<Self>) -> T { ... }
}
Expand description

A stateful source that produces animated values over time.

Required Methods§

Source

fn value(&self) -> &T

Returns the animation’s current value.

Source

fn state(&self) -> AnimationState

Returns the animation’s lifecycle state.

Source

fn tick(&mut self, delta: Duration)

Advances the animation by delta.

Source

fn pause(&mut self)

Pauses a running animation.

Source

fn resume(&mut self)

Resumes a paused animation.

Source

fn cancel(&mut self)

Cancels the animation.

Source

fn seek(&mut self, progress: f32)

Seeks to normalized progress within the animation.

Source

fn finish(&mut self)

Moves the animation to its completed state.

Provided Methods§

Source

fn duration(&self) -> Option<Duration>

Returns the total duration when it is finite and known.

Source

fn advance(&mut self, delta: Duration) -> Duration

Advances the animation and returns any unconsumed duration.

Source

fn retarget(&mut self, _target: &T) -> bool

Attempts to continue the animation toward a new target.

Returns true when the animation supports retargeting.

Source

fn is_active(&self) -> bool

Returns whether the animation is currently running.

Source

fn set_rate(&mut self, _rate: f64)

Updates playback rate by adjusting the animation’s stored durations.

The default implementation does nothing, which is appropriate for animations such as springs that are not duration-based.

Source

fn rate(self, rate: f64) -> Self
where Self: Sized,

Returns this animation with its playback rate adjusted.

A rate of 2.0 halves duration, while 0.5 doubles it. Repeated calls compound because implementations update duration directly instead of storing a separate rate value.

Source

fn into_value(self: Box<Self>) -> T

Consumes the animation and returns its current value.

The default implementation clones the sampled value so custom animations remain source-compatible. Implementations that own their sampled value should override this method to move it without cloning.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<Source, T> Animation<T> for Box<Source>
where T: Animatable, Source: Animation<T> + ?Sized,

Source§

fn value(&self) -> &T

Source§

fn state(&self) -> AnimationState

Source§

fn duration(&self) -> Option<Duration>

Source§

fn tick(&mut self, delta: Duration)

Source§

fn advance(&mut self, delta: Duration) -> Duration

Source§

fn pause(&mut self)

Source§

fn resume(&mut self)

Source§

fn cancel(&mut self)

Source§

fn seek(&mut self, progress: f32)

Source§

fn finish(&mut self)

Source§

fn retarget(&mut self, target: &T) -> bool

Source§

fn is_active(&self) -> bool

Source§

fn set_rate(&mut self, rate: f64)

Source§

fn into_value(self: Box<Box<Source>>) -> T

Implementors§

Source§

impl<S> Animation<S> for FieldsAnimation<S>
where S: Animatable,

Source§

impl<T> Animation<T> for Hold<T>
where T: Animatable,

Source§

impl<T> Animation<T> for Keyframes<T>
where T: Animatable,

Source§

impl<T> Animation<T> for Parallel<T>
where T: Animatable,

Source§

impl<T> Animation<T> for Sequence<T>
where T: Animatable,

Source§

impl<T> Animation<T> for Spring<T>
where T: Animatable,

Source§

impl<T> Animation<T> for Tween<T>
where T: Animatable,