cushy

Module animation

source
Expand description

Types for creating animations.

Animations in Cushy are performed by transitioning a Dynamic’s contained value over time. This starts with Dynamic::transition_to(), which returns a DynamicTransition.

DynamicTransition implements AnimationTarget, a trait that describes types that can be updated using linear interpolation. AnimationTarget is also implemented for tuples of AnimationTarget implementors, allowing multiple transitions to be an AnimationTarget.

Next, the AnimationTarget is turned into an animation by invoking AnimationTarget::over() with the Duration the transition should occur over. The animation can further be customized using Animation::with_easing() to utilize any Easing implementor.

use std::time::Duration;

use cushy::animation::easings::EaseInOutElastic;
use cushy::animation::{AnimationTarget, Spawn};
use cushy::value::{Dynamic, Source};

let value = Dynamic::new(0);
let mut reader = value.create_reader();
value
    .transition_to(100)
    .over(Duration::from_millis(100))
    .with_easing(EaseInOutElastic)
    .launch();
drop(value);

while reader.block_until_updated() {
    println!("{}", reader.get());
}

assert_eq!(reader.get(), 100);

Modules§

Structs§

Traits§

Derive Macros§