Glissade
Glissade is a Rust animations and transitions library. It's framework-agnostic with optional euclid, nalgebra, cgmath, and palette support. To make it work, you need to enable the corresponding feature.
The lib contains two main types: Animation and InertialValue.
Animationcan be used in cases when we know start, end, and in between keyframes.InertialValuecan be used to make an object smoothly follow a target value. For example, a particle following a cursor. Background color changing smoothly on theme change.
It also contains a set of easing functions to make animations more natural. See the Easing enum for more details.
Most of the methods receive std::time::Instant (or web_time::Instant depending on a platform) as a parameter to allow testing without mocks,
and have a consistent behavior during a single animation frame. It's expected that time is received
from Instant::now() once in the beginning of the frame, and used lately during the frame rendering.
Animation can be applied to any type that implements Mix trait. This trait is used to interpolate between two values.
Mix trait is implemented for common types like f32, f64, bool, i8 - i64, u8 - u64, Option<T: Mix>,
and tuples like (Mix, Mix), (Mix, Mix, Mix), etc. It's also implemented for some popular libraries:
nalgebra, euclid,
cgmath, and palette.
Derive macro
The library contains a derive macro to implement the Mix trait for structs and tuples.
use Mix;
let touch1 = Touch ;
let touch2 = Touch ;
let touch_mix = touch1.mix;
assert_eq!;
Cargo features
"derive"- enables derive macro forMixtrait (enabled by default)."euclid"- enables euclid vectors, rotations, etc. animation."nalgebra"- enables nalgebra vectors, matrices, transformations, etc. animation."cgmath"- enables cgmath vectors, matrices, etc. animation."palette"- enables palette colors interpolation.
Examples
Live
Simple two-step animation
use ;
use sleep;
use ;
const STEPS_COUNT: u32 = 10;
const STEP: Duration = from_millis;
Prints the following output:
0.00s: 0.0000
0.35s: 3.5000
0.70s: 7.0000
1.05s: 9.9935
1.40s: 9.5980
1.75s: 8.5862
2.10s: 7.0160
2.45s: 5.7480
2.80s: 5.0970
3.15s: 5.0000
Try it yourself with cargo run examples/console-transition, or view the source code in ./examples/console-transition.
Smoothly change color
use ;
use ;
type Color = ;
let start_time = now;
// Create initial black value
let value: = new;
assert_eq!;
assert_eq!;
// Change color to white in one second
let value = value.go_to;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Change color to red in between the transition
let value = value.ease_to;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
License
This project is licensed under the MIT License - see the LICENSE.md file for details.