Animated

Struct Animated 

Source
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: T

Implementations§

Source§

impl<T, Time> Animated<T, Time>

Source

pub fn new_with_settings(value: T, duration_ms: f32, easing: Easing) -> Self

Creates an animated value with specified animation settings

Source

pub fn new(value: T) -> Self

Creates an animated value with a default animation

Source

pub fn duration(self, duration_ms: f32) -> Self

Specifies the duration of the animation in milliseconds

Source

pub fn easing(self, easing: Easing) -> Self

Specifies the easing with which to animate transitions

Source

pub fn delay(self, delay_ms: f32) -> Self

Delays the animation by the given number of milliseconds

Source

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

Source

pub fn repeat_forever(self) -> Self

Repeats transitions forever

Source

pub fn auto_reverse(self) -> Self

Automatically play repetitions in reverse after they complete

Source

pub fn auto_start(self, new_value: T, at: Time) -> Self

Begins a transition as soon as the animation is created

Source

pub fn asymmetric_duration(self, duration_ms: f32) -> Self

Applies an alternative duration while animating backwards

Source

pub fn asymmetric_easing(self, easing: Easing) -> Self

Applies an alternative easing while animating backwards

Source

pub fn transition(&mut self, new_value: T, at: Time)

Updates the wrapped state & begins an animation

Source

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.

Source

pub fn in_progress(&self, time: Time) -> bool

Returns whether the animation is complete, given the current time

Source

pub fn animate<I>(&self, map: impl Fn(T) -> I, time: Time) -> I
where I: Interpolable,

Interpolates between states of any value that implements Interpolable, given the current time

Source§

impl<T, Time> Animated<T, Time>

Source

pub fn animate_if_eq<I>(&self, value: T, equal: I, default: I, time: Time) -> I
where 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>

Source

pub fn animate_wrapped(&self, time: Time) -> T

Source§

impl<Time> Animated<bool, Time>
where Time: AnimationTime,

Source

pub fn animate_bool<I>(&self, false_value: I, true_value: I, time: Time) -> I
where I: Interpolable + Clone,

Interpolates any value that implements Interpolable, given the current time

Trait Implementations§

Source§

impl<T, Time> Clone for Animated<T, Time>

Source§

fn clone(&self) -> Animated<T, Time>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, Time> Debug for Animated<T, Time>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, Time> Default for Animated<T, Time>

Source§

fn default() -> Animated<T, Time>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, Time> Freeze for Animated<T, Time>
where T: Freeze, Time: Freeze,

§

impl<T, Time> RefUnwindSafe for Animated<T, Time>
where T: RefUnwindSafe, Time: RefUnwindSafe,

§

impl<T, Time> Send for Animated<T, Time>
where T: Send,

§

impl<T, Time> Sync for Animated<T, Time>
where T: Sync, Time: Sync,

§

impl<T, Time> Unpin for Animated<T, Time>
where T: Unpin, Time: Unpin,

§

impl<T, Time> UnwindSafe for Animated<T, Time>
where T: UnwindSafe, Time: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.