Skip to main content

Tween

Struct Tween 

Source
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>

Source

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.

Source

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.

Source

pub fn with_ease(self, ease: Ease) -> Self

Selects the easing curve applied to each cycle.

Source

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.

Source

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.

Source

pub fn from(&self) -> T

Start value.

Source

pub fn to(&self) -> T

End value of a forward cycle.

Source

pub fn duration(&self) -> Duration

Duration of one cycle.

Source

pub fn delay(&self) -> Duration

Delay before the first cycle.

Source

pub fn ease(&self) -> Ease

Easing curve.

Source

pub fn mode(&self) -> TweenMode

Repetition behavior.

Source

pub fn completed_cycles(&self) -> u32

Completed cycles; saturates for endless repetition.

Source

pub fn progress(&self) -> f32

Un-eased progress through the current cycle, in [0, 1]; zero during the delay.

Source

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.

Source

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.

Source

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.

Source

pub fn with_id(self, id: TweenId) -> Self

Sets the identity reported on completion.

Source

pub fn id(&self) -> TweenId

Identity reported on completion.

Source

pub fn pause(&mut self)

Stops advancement; time supplied while paused is discarded.

Source

pub fn resume(&mut self)

Allows advancement again. Finished or cancelled playback stays so until reset.

Source

pub fn is_paused(&self) -> bool

Whether explicit time advancement is paused.

Source

pub fn reset(&mut self)

Rewinds to the start and rearms completion, preserving pause state.

Source

pub fn cancel(&mut self)

Stops at the current value without completing; Self::reset rearms.

Source

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.

Source

pub fn is_finished(&self) -> bool

Whether the end was reached (by advancing or Self::finish).

Source

pub fn is_cancelled(&self) -> bool

Whether Self::cancel stopped playback before the end.

Trait Implementations§

Source§

impl<T: Tweenable> Animate for Tween<T>

Source§

fn step(&mut self, dt: Duration) -> Option<Duration>

Advances unless paused, finished or cancelled. Returns the unused part of dt from the call that completes the animation, otherwise None.
Source§

fn rewind(&mut self)

Returns to the start and rearms completion, preserving pause state.
Source§

fn skip_to_end(&mut self)

Jumps to the final state and marks it finished, without reporting completion.
Source§

fn is_done(&self) -> bool

Whether finished or cancelled; a group skips done members.
Source§

impl<T: Clone> Clone for Tween<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for Tween<T>

Source§

impl<T: Debug> Debug for Tween<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for Tween<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Tween<T>

Auto Trait Implementations§

§

impl<T> Freeze for Tween<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Tween<T>
where T: RefUnwindSafe,

§

impl<T> Send for Tween<T>
where T: Send,

§

impl<T> Sync for Tween<T>
where T: Sync,

§

impl<T> Unpin for Tween<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Tween<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Tween<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.