pub struct Tween<T> { /* private fields */ }Expand description
Typed interpolation between two values with duration, delay, easing and repetition.
The delay applies once, before the first cycle. Repeating tweens run until
Self::with_cycles repetitions complete, or forever. Exact cycle boundaries
wrap to the next cycle; a finished tween holds its exact final value.
Self::finish on an endless tween ends its current cycle, so a ping-pong
leg running backward finishes at the start value.
Implementations§
Source§impl<T: Tweenable> Tween<T>
impl<T: Tweenable> Tween<T>
Sourcepub fn new(from: T, to: T, duration: Duration) -> Self
pub fn new(from: T, to: T, duration: Duration) -> Self
Linear one-shot tween without delay. A zero duration completes on its first advance, including a zero-length one.
Sourcepub fn with_delay(self, delay: Duration) -> Self
pub fn with_delay(self, delay: Duration) -> Self
Waits this long, holding the start value, before the first cycle. A tween already past its delay keeps running; the new delay applies after reset.
Sourcepub fn with_mode(self, mode: TweenMode) -> Self
pub fn with_mode(self, mode: TweenMode) -> Self
Selects one-shot, looping or ping-pong playback. Panics if a repeating mode is selected with a zero duration.
Sourcepub fn with_cycles(self, cycles: u32) -> Self
pub fn with_cycles(self, cycles: u32) -> Self
Completes a repeating tween after this many cycles; a ping-pong cycle is
one leg, so 2 goes there and back. Ignored by TweenMode::Once.
Panics for zero.
Sourcepub fn completed_cycles(&self) -> u32
pub fn completed_cycles(&self) -> u32
Completed cycles; saturates for endless repetition.
Sourcepub fn progress(&self) -> f32
pub fn progress(&self) -> f32
Un-eased progress through the current cycle, in [0, 1]; zero during the delay.
Sourcepub fn value(&self) -> T
pub fn value(&self) -> T
Current value. Reading never advances playback. The endpoints are returned exactly, so a finished tween reports precisely its final value.
Sourcepub fn retarget(&mut self, to: T)
pub fn retarget(&mut self, to: T)
Restarts toward a new end value from the current value, preserving duration, easing, mode, identity and pause state. The delay is skipped, so an interrupted UI slide turns around immediately instead of stalling.
Sourcepub fn advance(&mut self, dt: Duration) -> Option<TweenCompleted>
pub fn advance(&mut self, dt: Duration) -> Option<TweenCompleted>
Advances by explicitly supplied time. Returns one completion on the call that reaches the end; paused, finished and cancelled playback do nothing.
Sourcepub fn resume(&mut self)
pub fn resume(&mut self)
Allows advancement again. Finished or cancelled playback stays so until reset.
Sourcepub fn cancel(&mut self)
pub fn cancel(&mut self)
Stops at the current value without completing; Self::reset rearms.
Sourcepub fn finish(&mut self) -> Option<TweenCompleted>
pub fn finish(&mut self) -> Option<TweenCompleted>
Jumps to the final value and returns the completion immediately, even
while paused. Returns None if already finished or cancelled.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the end was reached (by advancing or Self::finish).
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether Self::cancel stopped playback before the end.
Trait Implementations§
Source§impl<T: Tweenable> Animate for Tween<T>
impl<T: Tweenable> Animate for Tween<T>
Source§fn step(&mut self, dt: Duration) -> Option<Duration>
fn step(&mut self, dt: Duration) -> Option<Duration>
dt from the call that completes the animation, otherwise None.