pub struct Tween<T: Interpolable + Copy> { /* private fields */ }Expand description
A generic tween interpolating a value of type T from a start to an end
value over a fixed duration, driven by an Easing curve.
Works with any type implementing Interpolable — the engine provides
implementations for f64, Vector2D, Vector3D, and Color.
§Why hand-written accessors
Lombok’s Data derive is intentionally not applied here for the same
reason as EngineCell: the derive does not propagate generic bounds, so
deriving on Tween<T> would force T: Default-style bounds that
Interpolable types do not carry. The accessor pairs below follow the
same naming contract as the Lombok-generated ones (get_* / set_*).
Implementations§
Source§impl<T: Interpolable + Copy> Tween<T>
Implements creation, playback control, and value sampling for Tween.
impl<T: Interpolable + Copy> Tween<T>
Implements creation, playback control, and value sampling for Tween.
Sourcepub fn get_easing(&self) -> Easing
pub fn get_easing(&self) -> Easing
Sourcepub fn get_elapsed(&self) -> f64
pub fn get_elapsed(&self) -> f64
Returns the time elapsed since creation, including the delay phase.
§Returns
f64: The elapsed time in seconds.
Sourcepub fn get_elapsed_mut(&mut self) -> &mut f64
pub fn get_elapsed_mut(&mut self) -> &mut f64
Returns a mutable reference to the elapsed time.
§Returns
&mut f64: The mutable elapsed time in seconds.
Sourcepub fn get_mode(&self) -> AnimationMode
pub fn get_mode(&self) -> AnimationMode
Returns what happens when the tween reaches the end of its duration.
§Returns
AnimationMode: The completion mode.
Sourcepub fn get_direction(&self) -> f64
pub fn get_direction(&self) -> f64
Returns the current playback direction for ping-pong mode.
§Returns
f64: The playback direction (1.0 = forward, -1.0 = backward).
Sourcepub fn try_get_on_complete(&self) -> &Option<Rc<dyn Fn()>>
pub fn try_get_on_complete(&self) -> &Option<Rc<dyn Fn()>>
Returns a reference to the optional completion callback slot.
§Returns
&Option<Rc<dyn Fn()>>: The completion callback slot.
Sourcepub fn set_easing(&mut self, easing: Easing)
pub fn set_easing(&mut self, easing: Easing)
Sourcepub fn set_elapsed(&mut self, elapsed: f64)
pub fn set_elapsed(&mut self, elapsed: f64)
Sourcepub fn set_state(&mut self, state: TweenState)
pub fn set_state(&mut self, state: TweenState)
Sourcepub fn set_mode(&mut self, mode: AnimationMode)
pub fn set_mode(&mut self, mode: AnimationMode)
Sets what happens when the tween reaches the end of its duration.
§Arguments
AnimationMode: The completion mode.
Sourcepub fn set_direction(&mut self, direction: f64)
pub fn set_direction(&mut self, direction: f64)
Sets the current playback direction for ping-pong mode.
§Arguments
f64: The playback direction (1.0 = forward, -1.0 = backward).
Sourcepub fn set_on_complete(&mut self, on_complete: Option<Rc<dyn Fn()>>)
pub fn set_on_complete(&mut self, on_complete: Option<Rc<dyn Fn()>>)
Sourcepub fn create(from: T, to: T, duration: f64) -> Tween<T>
pub fn create(from: T, to: T, duration: f64) -> Tween<T>
Creates a new linear tween from from to to over duration seconds.
The tween starts in the Delayed state only when a delay is later
attached via Tween::with_delay; by default it starts Running.
§Arguments
T: Interpolable + Copy- The start value.T: Interpolable + Copy- The end value.f64- The interpolation duration in seconds.
§Returns
Tween<T: Interpolable + Copy>- The new tween.
Sourcepub fn with_easing(self, easing: Easing) -> Tween<T>
pub fn with_easing(self, easing: Easing) -> Tween<T>
Sourcepub fn with_delay(self, delay: f64) -> Tween<T>
pub fn with_delay(self, delay: f64) -> Tween<T>
Sourcepub fn with_mode(self, mode: AnimationMode) -> Tween<T>
pub fn with_mode(self, mode: AnimationMode) -> Tween<T>
Sourcepub fn with_on_complete(self, on_complete: Rc<dyn Fn()>) -> Tween<T>
pub fn with_on_complete(self, on_complete: Rc<dyn Fn()>) -> Tween<T>
Sourcepub fn value(&self) -> T
pub fn value(&self) -> T
Returns the current interpolated value without advancing time.
§Returns
T: Interpolable + Copy- The current eased value.
Sourcepub fn eased_progress(&self) -> f64
pub fn eased_progress(&self) -> f64
Returns the eased progress of the current cycle in the range 0.0 to 1.0.
§Returns
f64- The eased progress.
Sourcepub fn raw_progress(&self) -> f64
pub fn raw_progress(&self) -> f64
Returns the raw (uneased) progress of the current cycle.
§Returns
f64- The raw progress in the range 0.0 to 1.0.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns whether the tween has finished (AnimationMode::Once only).
§Returns
bool- True if the tween is finished.