lustre/animation
Types
A singleton holding all your animations, and a timestamp
pub opaque type Animations
pub external type RequestedFrame
Functions
pub fn add(animations: Animations, name: String, start: Float, stop: Float, seconds: Float) -> Animations
Add an animation (linear interpolation) from start
to stop
, for seconds
duration.
The name
should be unique, so the animation can be retrieved and evaluated by value()
later.
The animation is started when a subsequent command from cmd()
is returned by your
lustre update()
function; followed by a call to tick()
.
pub external fn cancel_animation_frame(
frame: RequestedFrame,
) -> Nil
pub fn cmd(animations: Animations, msg: fn(Float) -> a) -> Cmd(a)
Returns cmd.none()
if none of the animations is running.
Otherwise returns an opaque Cmd
that will cause msg(time)
to
be dispatched on a JavaScript requestAnimationFrame
pub fn new() -> Animations
pub fn remove(animations: Animations, name: String) -> Animations
Remove an animation if it should stop before it is finished.
If an animation runs to its end normally, you do not have to remove()
it manually,
will be automatically removed by tick()
.
pub fn request_animation_frame(msg: fn(Float) -> a) -> Cmd(a)
pub fn tick(animations: Animations, time_offset: Float) -> Animations
When called for the first time on an animation, its start time is set to time-Offset. Its stop time then is the start time plus the duration.
When called for the first time for animations that have finished,
they will be marked as such in the result. value()
will return the stop
value
that you passed with add()
When called the second time for animations that have finished, they will be absent from the returned value.
pub fn value(animations: Animations, which: String, default: Float) -> Float
If the animation specified by which
is not found, returns default
.
Otherwise, the interpolated value for the time
passed to tick()
is returned.