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 SystemTime 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 SystemTime::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
Simple two-step animation
use ;
use ;
// Create an animation template - a transition.
//
// This transition consists of two steps:
// 1. from 0.0 to 10.0 in 1 second linearly,
// 2. and then go to 5.0 with easing function.
let transition = transition
.go_to
.ease_to;
let now = now;
// Create an animation from the transition and start time.
let animation = transition.run;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
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.