pub struct Animated<T, Time>{
pub value: T,
/* private fields */
}Expand description
Wraps state to enable interpolated transitions
§Example
use lilt::Animated;
use std::time::Instant;
struct MyViewState {
animated_toggle: Animated<bool, Instant>,
}
// Initialize
let mut state = MyViewState {
animated_toggle: Animated::new(false),
};
// Update
let now = std::time::Instant::now();
state
.animated_toggle
.transition(!state.animated_toggle.value, now);
// Animate
let animated_width = state.animated_toggle.animate_bool(0., 100., now);
let animated_width = state.animated_toggle.animate(
|on| if on { 0. } else { 100. },
now,
);An Animated struct represents a single animation axis. Multiple axes require multiple Animated structs.
For example - to animate an x and a y position on the screen with different durations you’d need to
wrap multiple float values independently.
use std::time::Instant;
use lilt::Animated;
struct MyState {
animated_x: Animated<f32, Instant>,
animated_y: Animated<f32, Instant>,
}Fields§
§value: TImplementations§
Source§impl<T, Time> Animated<T, Time>
impl<T, Time> Animated<T, Time>
Sourcepub fn new_with_settings(value: T, duration_ms: f32, easing: Easing) -> Self
pub fn new_with_settings(value: T, duration_ms: f32, easing: Easing) -> Self
Creates an animated value with specified animation settings
Sourcepub fn duration(self, duration_ms: f32) -> Self
pub fn duration(self, duration_ms: f32) -> Self
Specifies the duration of the animation in milliseconds
Sourcepub fn easing(self, easing: Easing) -> Self
pub fn easing(self, easing: Easing) -> Self
Specifies the easing with which to animate transitions
Sourcepub fn delay(self, delay_ms: f32) -> Self
pub fn delay(self, delay_ms: f32) -> Self
Delays the animation by the given number of milliseconds
Sourcepub fn repeat(self, count: u32) -> Self
pub fn repeat(self, count: u32) -> Self
Repeats animations the specified number of times Passing a repetition count of 1 plays the animation twice in total
Sourcepub fn repeat_forever(self) -> Self
pub fn repeat_forever(self) -> Self
Repeats transitions forever
Sourcepub fn auto_reverse(self) -> Self
pub fn auto_reverse(self) -> Self
Automatically play repetitions in reverse after they complete
Sourcepub fn auto_start(self, new_value: T, at: Time) -> Self
pub fn auto_start(self, new_value: T, at: Time) -> Self
Begins a transition as soon as the animation is created
Sourcepub fn asymmetric_duration(self, duration_ms: f32) -> Self
pub fn asymmetric_duration(self, duration_ms: f32) -> Self
Applies an alternative duration while animating backwards
Sourcepub fn asymmetric_easing(self, easing: Easing) -> Self
pub fn asymmetric_easing(self, easing: Easing) -> Self
Applies an alternative easing while animating backwards
Sourcepub fn transition(&mut self, new_value: T, at: Time)
pub fn transition(&mut self, new_value: T, at: Time)
Updates the wrapped state & begins an animation
Sourcepub fn transition_instantaneous(&mut self, new_value: T, at: Time)
pub fn transition_instantaneous(&mut self, new_value: T, at: Time)
Updates the wrapped state & instantaneously completes an animation. Ignores animation settings such as delay & duration.
Sourcepub fn in_progress(&self, time: Time) -> bool
pub fn in_progress(&self, time: Time) -> bool
Returns whether the animation is complete, given the current time
Sourcepub fn animate<I>(&self, map: impl Fn(T) -> I, time: Time) -> Iwhere
I: Interpolable,
pub fn animate<I>(&self, map: impl Fn(T) -> I, time: Time) -> Iwhere
I: Interpolable,
Interpolates between states of any value that implements Interpolable, given the current time
Source§impl<T, Time> Animated<T, Time>
impl<T, Time> Animated<T, Time>
Sourcepub fn animate_if_eq<I>(&self, value: T, equal: I, default: I, time: Time) -> Iwhere
I: Interpolable + Clone,
pub fn animate_if_eq<I>(&self, value: T, equal: I, default: I, time: Time) -> Iwhere
I: Interpolable + Clone,
Interpolates to equal when the wrapped value matches the provided value
Otherwise interpolate towards default
Source§impl<T, Time> Animated<T, Time>
impl<T, Time> Animated<T, Time>
pub fn animate_wrapped(&self, time: Time) -> T
Source§impl<Time> Animated<bool, Time>where
Time: AnimationTime,
impl<Time> Animated<bool, Time>where
Time: AnimationTime,
Sourcepub fn animate_bool<I>(&self, false_value: I, true_value: I, time: Time) -> Iwhere
I: Interpolable + Clone,
pub fn animate_bool<I>(&self, false_value: I, true_value: I, time: Time) -> Iwhere
I: Interpolable + Clone,
Interpolates any value that implements Interpolable, given the current time