pub trait Tweenable<T>: Send + Sync {
    // Required methods
    fn duration(&self) -> Duration;
    fn total_duration(&self) -> TotalDuration;
    fn set_elapsed(&mut self, elapsed: Duration);
    fn elapsed(&self) -> Duration;
    fn tick(
        &mut self,
        delta: Duration,
        target: &mut dyn Targetable<T>,
        entity: Entity,
        events: &mut Mut<'_, Events<TweenCompleted>>
    ) -> TweenState;
    fn rewind(&mut self);

    // Provided methods
    fn set_progress(&mut self, progress: f32) { ... }
    fn progress(&self) -> f32 { ... }
    fn times_completed(&self) -> u32 { ... }
}
Expand description

An animatable entity, either a single Tween or a collection of them.

Required Methods§

source

fn duration(&self) -> Duration

Get the duration of a single iteration of the animation.

Note that for RepeatStrategy::MirroredRepeat, this is the duration of a single way, either from start to end or back from end to start. The total “loop” duration start -> end -> start to reach back the same state in this case is the double of the returned value.

source

fn total_duration(&self) -> TotalDuration

Get the total duration of the entire animation, including looping.

For TotalDuration::Finite, this is the number of repeats times the duration of a single iteration (duration()).

source

fn set_elapsed(&mut self, elapsed: Duration)

Set the current animation playback elapsed time.

See elapsed() for details on the meaning. If elapsed is greater than or equal to duration(), then the animation completes.

Setting the elapsed time seeks the animation to a new position, but does not apply that change to the underlying component being animated. To force the change to apply, call tick() with a delta of Duration::ZERO.

source

fn elapsed(&self) -> Duration

Get the current elapsed duration.

While looping, the exact value returned by duration() is never reached, since the tweenable loops over to zero immediately when it changes direction at either endpoint. Upon completion, the tweenable always reports the same value as duration().

source

fn tick( &mut self, delta: Duration, target: &mut dyn Targetable<T>, entity: Entity, events: &mut Mut<'_, Events<TweenCompleted>> ) -> TweenState

Tick the animation, advancing it by the given delta time and mutating the given target component or asset.

This returns TweenState::Active if the tweenable didn’t reach its final state yet (progress < 1.0), or TweenState::Completed if the tweenable completed this tick. Only non-looping tweenables return a completed state, since looping ones continue forever.

Calling this method with a duration of Duration::ZERO is valid, and updates the target to the current state of the tweenable without actually modifying the tweenable state. This is useful after certain operations like rewind() or set_progress() whose effect is otherwise only visible on target on next frame.

source

fn rewind(&mut self)

Rewind the animation to its starting state.

Note that the starting state depends on the current direction. For TweeningDirection::Forward this is the start point of the lens, whereas for TweeningDirection::Backward this is the end one.

Provided Methods§

source

fn set_progress(&mut self, progress: f32)

Set the current animation playback progress.

See progress() for details on the meaning.

Setting the progress seeks the animation to a new position, but does not apply that change to the underlying component being animated. To force the change to apply, call tick() with a delta of Duration::ZERO.

source

fn progress(&self) -> f32

Get the current progress in [0:1] of the animation.

While looping, the exact value 1.0 is never reached, since the tweenable loops over to 0.0 immediately when it changes direction at either endpoint. Upon completion, the tweenable always reports exactly 1.0.

source

fn times_completed(&self) -> u32

Get the number of times this tweenable completed.

For looping animations, this returns the number of times a single playback was completed. In the case of RepeatStrategy::MirroredRepeat this corresponds to a playback in a single direction, so tweening from start to end and back to start counts as two completed times (one forward, one backward).

Implementors§

source§

impl<T> Tweenable<T> for Delay<T>

source§

impl<T> Tweenable<T> for Sequence<T>

source§

impl<T> Tweenable<T> for Tracks<T>

source§

impl<T> Tweenable<T> for Tween<T>