Module tween

Source
Expand description

Easing curves, tweens, springs and UI/screen transition timing.

Everything here is Copy, allocation-free and advanced by a caller-supplied dt in seconds, so presentation stays deterministic for a given sequence of timesteps (subject to the platform’s exp/sin/powf, as with crate::motion). Nothing reads a clock. Drive these from the frame delta for menus and HUD polish; drive them from the fixed tick when the motion is part of gameplay timing.

Reduced motion is an explicit Motion argument. Build it from the player’s FeedbackPolicy with Motion::from(policy). Under Motion::Reduced tweens and springs snap to their targets, entrances only fade, roll counters show the final number and screen transitions become plain fades.

use ferravex_play::tween::{Ease, Motion, Spring, Tween};
let mut fade = Tween::new(0., 1., 0.25, Ease::CubicOut);
let mut scale = Spring::underdamped(0.8, 6., 0.45);
scale.set_target(1.);
for _ in 0..30 {
    let alpha = fade.advance(1. / 60., Motion::Full);
    let s = scale.advance(1. / 60., Motion::Full);
    assert!((0. ..=1.).contains(&alpha) && s.is_finite());
}
assert!(fade.is_finished() && fade.value() == 1.);

Structs§

Appearance
How a staggered UI element appears at one instant: multiply its alpha, translate it by offset and scale it about its center by scale.
Entrance
Fade/slide/scale entrance shared by a list of elements with a per-item stagger. Sample with the time since the list opened; play it backwards (decreasing elapsed) for an exit.
RollCounter
An integer display that rolls toward its target, like a score counter. Every roll takes duration seconds regardless of size (eased, quick start and gentle landing) and the shown number never passes the target.
ScreenTransition
Cover → swap → reveal timing for scene changes (wipe, iris or fade). Under reduced motion ScreenTransition::kind reports TransitionKind::Fade.
Spring
A damped harmonic spring toward target, integrated analytically so any dt is stable and splitting a step gives the same result (up to rounding).
Tween
A one-shot eased transition from from to to over duration seconds, optionally after a delay. Non-finite or negative timesteps count as zero; a nonpositive duration finishes immediately.

Enums§

Ease
Standard easing curves. Ease::apply maps t in [0, 1] (clamped) to eased progress with exact endpoints 0 → 0 and 1 → 1. Back and elastic curves overshoot outside [0, 1] in between; bounce stays inside it.
Motion
Whether presentation motion is full or reduced for accessibility.
TransitionEvent
Completion edge reported once by ScreenTransition::advance.
TransitionKind
Visual style of a ScreenTransition. Drawing lives in the renderer (ferravex_render::ui::kit::draw_screen_transition).
TransitionPhase
What a ScreenTransition is doing.

Functions§

lerp
Linear interpolation a + (b - a) * t (t is not clamped).