plushie/animation/tween
SDK-side frame-based interpolation (manual tween).
For most use cases, prefer renderer-side descriptors
(plushie/animation/transition, plushie/animation/spring)
which animate with zero wire traffic. Use this module when you
need frame-by-frame control over interpolation in the app model.
Drive with subscription.on_animation_frame(), create with new,
start with start, then advance each frame.
Types
An animation interpolating between two values over time.
pub type Animation {
Animation(
from: Float,
to: Float,
duration_ms: Int,
started_at: option.Option(Int),
easing: easing.Easing,
value: Float,
finished: Bool,
repeat: Repeat,
auto_reverse: Bool,
cycles_completed: Int,
reversed: Bool,
)
}
Constructors
-
Animation( from: Float, to: Float, duration_ms: Int, started_at: option.Option(Int), easing: easing.Easing, value: Float, finished: Bool, repeat: Repeat, auto_reverse: Bool, cycles_completed: Int, reversed: Bool, )Arguments
- cycles_completed
-
Track how many complete cycles have been played.
- reversed
-
Track whether the current cycle is playing forward or reversed.
Values
pub fn advance(anim: Animation, now: Int) -> Animation
Advance the animation to the given timestamp. Returns updated animation.
Check finished field to know when it’s done.
pub fn lerp(from: Float, to: Float, t: Float) -> Float
Linear interpolation between two values.
pub fn looping(
from: Float,
to: Float,
duration_ms: Int,
easing: easing.Easing,
) -> Animation
Create a looping animation that repeats forever with auto-reverse.
Shorthand for new with repeat: Forever and auto_reverse: True.
The animation bounces between from and to indefinitely.
pub fn new(
from: Float,
to: Float,
duration_ms: Int,
easing: easing.Easing,
) -> Animation
Create a new animation (not yet started).
Uses the same Easing type as renderer-side transitions, so the
full set of named curves is available (e.g. easing.EaseOutBounce,
easing.CubicBezier(0.25, 0.1, 0.25, 1.0)).
pub fn set_auto_reverse(
anim: Animation,
enabled: Bool,
) -> Animation
Enable or disable auto-reverse. When enabled, the animation plays in reverse on alternate cycles.
pub fn set_repeat(anim: Animation, repeat: Repeat) -> Animation
Set the repeat mode on an animation.