#animation #transition #interpolation #state #time #easing #gui

lilt

A simple, dependency free library for running interruptable, transition based animations as a function of time

14 releases (8 breaking)

0.8.0 Jan 28, 2025
0.7.0 Aug 17, 2024
0.6.1 Aug 11, 2024
0.6.0 Jul 12, 2024

#178 in Algorithms

Download history 10/week @ 2024-10-25 11/week @ 2024-11-01 9/week @ 2024-11-08 4/week @ 2024-11-15 6/week @ 2024-11-22 2/week @ 2024-11-29 34/week @ 2024-12-06 9/week @ 2024-12-13 1/week @ 2024-12-20 1/week @ 2025-01-03 12/week @ 2025-01-10 7/week @ 2025-01-17 1155/week @ 2025-01-24 2503/week @ 2025-01-31 1572/week @ 2025-02-07

5,239 downloads per month

MIT license

51KB
1K SLoC

Lilt

rust coverage crates.io docs.rs downloads license

A simple library for running interruptable, transition based animations as a function of time.

This library only implements animations & would be most useful along with a GUI library that can do GUI things (like iced).

Getting Started

Define

Embed the state you want to animate in an Animated struct.

struct MyViewState {
    toggle: Animated<bool, Instant>,
}

When you initialize your view state - define the initial state & configure the animation to your liking.

let mut state = MyViewState {
    toggle: Animated::new(false)
        .duration(300.)
        .easing(Easing::EaseOut)
        .delay(30.)
        .repeat(3),
};

Transition

When your state needs an update, call the transition function on your animated state, passing the current time.

let now = std::time::Instant::now();
state
    .toggle
    .transition(!state.animated_toggle.value, now);

Render

While rendering a view based on your state - use the animate function on your state to get the interpolated value for the current frame.

let now = std::time::Instant::now();

// The wrapped value can be used to interpolate any values that implement `Interpolable`
let animated_width = self.toggle.animate_bool(100., 500., now);

// If the wrapped value itself is `Interpolable`, it can easily be interpolated in place
let animated_width = self.width.animate_wrapped(now);

// There are plenty of `animate` methods for interpolating things based on the wrapped value.

What's the point?

lilt emerged from the need for ELM compatible / reactive animations.

The animations modeled by this library don't require periodic mutation like a 'tick' function - all interim states of the animation are predefined when 'transition' is called, & then accessed while rendering based on the current time.

lilt animations are fully independent of frame rate or tick frequency & only need to be computed if they're used during rendering.

Examples

indicator

Dependencies

~38–275KB