Skip to main content

Tween

Struct Tween 

Source
pub struct Tween<T: Animatable> {
    pub start: T,
    pub end: T,
    pub duration: f32,
    pub easing: Easing,
    pub delay: f32,
    pub time_scale: f32,
    pub looping: Loop,
    /* private fields */
}
Expand description

A single-value animation from start to end over duration seconds.

Build with Tween::new and the consuming builder chain:

use animato_tween::Tween;
use animato_core::Easing;

let mut t = Tween::new(0.0_f32, 100.0)
    .duration(1.5)
    .easing(Easing::EaseOutCubic)
    .delay(0.2)
    .build();

§no_std

Tween<T> is stack-allocated — no heap allocation occurs in update() or value().

Fields§

§start: T

The value at t = 0.

§end: T

The value at t = duration.

§duration: f32

Total animation duration in seconds. Clamped to ≥ 0.

§easing: Easing

Easing curve applied to the normalised progress.

§delay: f32

Delay in seconds before the animation begins.

§time_scale: f32

Time scale multiplier. 1.0 = normal, 2.0 = double speed.

§looping: Loop

Looping behaviour.

Implementations§

Source§

impl<T: Animatable> Tween<T>

Source

pub fn new(start: T, end: T) -> TweenBuilder<T>

Begin building a tween from start to end.

use animato_tween::Tween;
use animato_core::Easing;

let t = Tween::new(0.0_f32, 1.0)
    .duration(2.0)
    .easing(Easing::EaseInOutSine)
    .build();
Source§

impl<T: Animatable> Tween<T>

Source

pub fn value(&self) -> T

The current interpolated value.

This is the hot path — no allocation, just a lerp.

use animato_tween::Tween;
use animato_core::Easing;

let t = Tween::new(0.0_f32, 100.0).duration(1.0).build();
assert_eq!(t.value(), 0.0); // hasn't started yet
Source

pub fn progress(&self) -> f32

Normalised progress in [0.0, 1.0] — raw, before easing.

Source

pub fn eased_progress(&self) -> f32

Normalised progress after easing is applied.

Source

pub fn is_complete(&self) -> bool

true when the tween has finished all its loops.

Source

pub fn state(&self) -> &TweenState

Current execution state.

Source

pub fn reset(&mut self)

Reset to the very beginning, including delay and loop counter.

Source

pub fn seek(&mut self, t: f32)

Jump to a normalised time t ∈ [0, 1] within the current pass.

Does not affect loop count or ping-pong direction.

Source

pub fn reverse(&mut self)

Swap start and end in place.

The animation immediately plays toward the new end.

When called mid-animation, the current visual position is preserved — elapsed is mirrored so the object appears to continue from where it is.

§Example
use animato_tween::Tween;
use animato_core::{Easing, Update};

let mut t = Tween::new(0.0_f32, 100.0)
    .duration(1.0)
    .easing(Easing::Linear)
    .build();
// Advance 30% of the way
t.update(0.3);
assert!((t.value() - 30.0).abs() < 1.0);
// Reverse — now at 70% of the backward journey (100→0)
t.reverse();
assert!((t.value() - 30.0).abs() < 1.0); // same visual position
Source

pub fn pause(&mut self)

Pause — update() calls become no-ops until resume.

Source

pub fn resume(&mut self)

Resume from a paused state.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Tween<T>

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: Debug + Animatable> Debug for Tween<T>

Source§

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

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

impl<T: Animatable> Playable for Tween<T>

Source§

fn duration(&self) -> f32

Total finite duration in seconds.
Source§

fn reset(&mut self)

Reset the animation to its initial state.
Source§

fn seek_to(&mut self, progress: f32)

Seek to normalized progress through the animation.
Source§

fn is_complete(&self) -> bool

true when the animation has reached its terminal state.
Source§

fn as_any(&self) -> &dyn Any

Return a type-erased shared reference for downcasting.
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Return a type-erased mutable reference for downcasting.
Source§

impl<T: Animatable> Update for Tween<T>

Source§

fn update(&mut self, dt: f32) -> bool

Advance the tween by dt seconds.

Returns true while still running, false when complete. Negative dt is treated as 0.0.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.