pub struct Tween {
pub from: f32,
pub to: f32,
pub duration: f32,
pub curve: Curve,
}Expand description
Injected-clock tween of a scalar from from→to over duration seconds,
eased by a Curve. The single “animate a value over a duration” primitive the
form facets were missing (hover/selection/expand, drawer slide-ins).
Determinism (FC-7): a Tween holds no egui state and no wall-clock — you
evaluate it at the elapsed seconds you own (the same dt/clock model as
SmoothScroll and focus::motion_progress),
so snapshots stay reproducible. It is a pure value, Copy, cheap to rebuild each frame.
use facett_core::effects::{Tween, Curve};
let t = Tween::new(0.0, 100.0, 0.2, Curve::EaseInOutCubic);
assert_eq!(t.value_at(0.0), 0.0); // start
assert_eq!(t.value_at(0.2), 100.0); // end
assert!(t.is_done(0.2));Fields§
§from: f32Value at elapsed <= 0.
to: f32Value at elapsed >= duration.
duration: f32Tween length in seconds. <= 0 snaps instantly to to (honours Motion::duration == 0,
the reduced-motion / Device setting).
curve: CurveEasing curve.
Implementations§
Source§impl Tween
impl Tween
Sourcepub fn new(from: f32, to: f32, duration: f32, curve: Curve) -> Self
pub fn new(from: f32, to: f32, duration: f32, curve: Curve) -> Self
A tween from→to over duration seconds with curve.
Sourcepub fn from_motion(motion: &Motion, from: f32, to: f32, curve: Curve) -> Self
pub fn from_motion(motion: &Motion, from: f32, to: f32, curve: Curve) -> Self
A standard-duration tween from the theme’s Motion token.
Sourcepub fn from_motion_fast(
motion: &Motion,
from: f32,
to: f32,
curve: Curve,
) -> Self
pub fn from_motion_fast( motion: &Motion, from: f32, to: f32, curve: Curve, ) -> Self
A faster tween using Motion::fast — for small/cheap transitions.
Sourcepub fn value_at(&self, elapsed: f32) -> f32
pub fn value_at(&self, elapsed: f32) -> f32
Eased value at elapsed seconds since the tween started.
value_at(<=0) == from, value_at(>=duration) == to; duration <= 0 ⇒ to.
Sourcepub fn progress_at(&self, elapsed: f32) -> f32
pub fn progress_at(&self, elapsed: f32) -> f32
Eased progress ∈[0,1] (the to-fraction) at elapsed — the lerp factor
to drive geometry/colour interpolation yourself.