Skip to main content

euv_engine/tween/
struct.rs

1use super::*;
2
3/// A generic tween interpolating a value of type `T` from a start to an end
4/// value over a fixed duration, driven by an [`Easing`] curve.
5///
6/// Works with any type implementing [`Interpolable`] — the engine provides
7/// implementations for `f64`, [`Vector2D`], [`Vector3D`], and [`Color`].
8///
9/// ## Why hand-written accessors
10///
11/// Lombok's `Data` derive is intentionally **not** applied here for the same
12/// reason as [`EngineCell`]: the derive does not propagate generic bounds, so
13/// deriving on `Tween<T>` would force `T: Default`-style bounds that
14/// `Interpolable` types do not carry. The accessor pairs below follow the
15/// same naming contract as the Lombok-generated ones (`get_*` / `set_*`).
16pub struct Tween<T: Interpolable + Copy> {
17    /// The value at the start of the tween.
18    pub(crate) from: T,
19    /// The value at the end of the tween.
20    pub(crate) to: T,
21    /// The total interpolation duration in seconds.
22    pub(crate) duration: f64,
23    /// The easing curve applied to the normalized time.
24    pub(crate) easing: Easing,
25    /// The start delay in seconds before interpolation begins.
26    pub(crate) delay: f64,
27    /// The time elapsed since creation (including the delay phase).
28    pub(crate) elapsed: f64,
29    /// The current playback state.
30    pub(crate) state: TweenState,
31    /// What happens when the tween reaches the end of its duration.
32    pub(crate) mode: AnimationMode,
33    /// The current playback direction (1.0 = forward, -1.0 = backward) for ping-pong mode.
34    pub(crate) direction: f64,
35    /// An optional callback fired when the tween completes a cycle.
36    pub(crate) on_complete: Option<Rc<dyn Fn()>>,
37}