pub struct Keyframes { /* private fields */ }Expand description
Multi-stop keyframe animation over a fixed tick duration.
Keyframes is similar to CSS @keyframes: define multiple stops in the
normalized [0.0, 1.0] timeline, then sample the value with
Keyframes::value using the current render tick.
Stops are sorted by position when sampled. Each segment between adjacent stops can use its own easing function.
§Example
use slt::anim::{ease_in_cubic, ease_out_quad, Keyframes, LoopMode};
let mut keyframes = Keyframes::new(60)
.stop(0.0, 0.0)
.stop(0.5, 100.0)
.stop(1.0, 40.0)
.segment_easing(0, ease_out_quad)
.segment_easing(1, ease_in_cubic)
.loop_mode(LoopMode::PingPong);
keyframes.reset(10);
let _ = keyframes.value(40);Implementations§
Source§impl Keyframes
impl Keyframes
Sourcepub fn new(duration_ticks: u64) -> Self
pub fn new(duration_ticks: u64) -> Self
Create a new keyframe animation with total duration_ticks.
Uses linear easing by default and LoopMode::Once. Add stops with
Keyframes::stop, optionally configure easing, then call
Keyframes::reset before sampling.
Sourcepub fn stop(self, position: f64, value: f64) -> Self
pub fn stop(self, position: f64, value: f64) -> Self
Add a keyframe stop at normalized position with value.
position is clamped to [0.0, 1.0].
Sourcepub fn easing(self, f: fn(f64) -> f64) -> Self
pub fn easing(self, f: fn(f64) -> f64) -> Self
Set the default easing used for segments without explicit overrides.
Existing segments are updated to this easing, unless you later override
them with Keyframes::segment_easing.
Sourcepub fn segment_easing(self, segment_index: usize, f: fn(f64) -> f64) -> Self
pub fn segment_easing(self, segment_index: usize, f: fn(f64) -> f64) -> Self
Override easing for a specific segment index.
Segment 0 is between the first and second stop, segment 1 between
the second and third, and so on. Out-of-range indices are ignored.
Sourcepub fn loop_mode(self, mode: LoopMode) -> Self
pub fn loop_mode(self, mode: LoopMode) -> Self
Set loop behavior used after the first full pass.
Sourcepub fn on_complete(self, f: impl FnMut() + 'static) -> Self
pub fn on_complete(self, f: impl FnMut() + 'static) -> Self
Register a callback that runs once when the animation completes.
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Returns true if the animation finished in LoopMode::Once.