Struct Animation

Source
pub struct Animation<T>
where T: Clone + Copy + PartialEq + Float,
{ /* private fields */ }
Expand description

The animation of some particular state.

It tracks state changes and allows projecting interpolated values through time.

Implementations§

Source§

impl<T> Animation<T>
where T: Clone + Copy + PartialEq + Float,

Source

pub fn new(state: T) -> Self

Creates a new Animation with the given initial state.

Source

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

Sets the Easing function of the Animation.

See the Easing Functions Cheat Sheet for details!

Source

pub fn very_quick(self) -> Self

Sets the duration of the Animation to 100ms.

Source

pub fn quick(self) -> Self

Sets the duration of the Animation to 200ms.

Source

pub fn slow(self) -> Self

Sets the duration of the Animation to 400ms.

Source

pub fn very_slow(self) -> Self

Sets the duration of the Animation to 500ms.

Source

pub fn duration(self, duration: Duration) -> Self

Sets the duration of the Animation to the given value.

Source

pub fn delay(self, duration: Duration) -> Self

Sets a delay for the Animation.

Source

pub fn repeat(self, repetitions: u32) -> Self

Makes the Animation repeat a given amount of times.

Providing 1 repetition plays the animation twice in total.

Source

pub fn repeat_forever(self) -> Self

Makes the Animation repeat forever.

Source

pub fn auto_reverse(self) -> Self

Makes the Animation automatically reverse when repeating.

Source

pub fn go(self, new_state: T, at: Instant) -> Self

Transitions the Animation from its current state to the given new state at the given time.

Source

pub fn go_mut(&mut self, new_state: T, at: Instant)

Transitions the Animation from its current state to the given new state at the given time, by reference.

Source

pub fn is_animating(&self, at: Instant) -> bool

Returns true if the Animation is currently in progress.

An Animation is in progress when it is transitioning to a different state.

Source

pub fn interpolate_with<I>(&self, f: impl Fn(T) -> I, at: Instant) -> I
where I: Interpolable,

Projects the Animation into an interpolated value at the given Instant; using the closure provided to calculate the different keyframes of interpolated values.

If the Animation state is a bool, you can use the simpler interpolate method.

Source

pub fn value(&self) -> T

Retuns the current state of the Animation.

Source§

impl Animation<bool>

Source

pub fn interpolate<I>(&self, start: I, end: I, at: Instant) -> I
where I: Interpolable + Clone,

Projects the Animation into an interpolated value at the given Instant; using the start and end values as the origin and destination keyframes.

Source

pub fn remaining(&self, at: Instant) -> Duration

Returns the remaining Duration of the Animation.

Trait Implementations§

Source§

impl<T> Clone for Animation<T>
where T: Clone + Copy + PartialEq + Float + Clone,

Source§

fn clone(&self) -> Animation<T>

Returns a copy 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> Debug for Animation<T>
where T: Clone + Copy + PartialEq + Float + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Animation<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Animation<T>
where T: RefUnwindSafe,

§

impl<T> Send for Animation<T>
where T: Send,

§

impl<T> Sync for Animation<T>
where T: Sync,

§

impl<T> Unpin for Animation<T>
where T: Unpin,

§

impl<T> UnwindSafe for Animation<T>
where T: 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T