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: TThe value at t = 0.
end: TThe value at t = duration.
duration: f32Total animation duration in seconds. Clamped to ≥ 0.
easing: EasingEasing curve applied to the normalised progress.
delay: f32Delay in seconds before the animation begins.
time_scale: f32Time scale multiplier. 1.0 = normal, 2.0 = double speed.
looping: LoopLooping behaviour.
Implementations§
Source§impl<T: Animatable> Tween<T>
impl<T: Animatable> Tween<T>
Sourcepub fn new(start: T, end: T) -> TweenBuilder<T>
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>
impl<T: Animatable> Tween<T>
Sourcepub fn value(&self) -> T
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 yetSourcepub fn eased_progress(&self) -> f32
pub fn eased_progress(&self) -> f32
Normalised progress after easing is applied.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
true when the tween has finished all its loops.
Sourcepub fn state(&self) -> &TweenState
pub fn state(&self) -> &TweenState
Current execution state.
Sourcepub fn seek(&mut self, t: f32)
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.
Sourcepub fn reverse(&mut self)
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 positionTrait Implementations§
Source§impl<T: Animatable> Playable for Tween<T>
impl<T: Animatable> Playable for Tween<T>
Source§fn is_complete(&self) -> bool
fn is_complete(&self) -> bool
true when the animation has reached its terminal state.