Skip to main content

Tween

Struct Tween 

Source
pub struct Tween<T: Animatable> { /* private fields */ }
Expand description

An animation that interpolates between two values using Timing.

§Examples

use aura_anim_core::{Tween, timing::Timing};
use std::time::Duration;

let mut tween = Tween::between(0.0_f32, 10.0, Timing::new(100.0));

tween.tick(Duration::from_millis(50));
assert_eq!(*tween.value(), 5.0);

tween.tick(Duration::from_millis(50));
assert!(tween.is_completed());
assert_eq!(*tween.value(), 10.0);

Implementations§

Source§

impl<T: Animatable> Tween<T>

Source

pub fn new(value: T) -> Self

Creates an idle tween with the default 200 millisecond timing.

Source

pub fn with_timing(value: T, timing: Timing) -> Self

Creates an idle tween with the provided timing.

Source

pub fn between(from: T, to: T, timing: Timing) -> Self

Creates a running tween from from to to.

Source

pub fn value(&self) -> &T

Returns the current interpolated value.

Source

pub fn from(&self) -> &T

Returns the value at the start of the current transition.

Source

pub fn target(&self) -> &T

Returns the target value of the current transition.

Source

pub const fn timing(&self) -> Timing

Returns the timing configuration.

Source

pub const fn state(&self) -> AnimationState

Returns the current lifecycle state.

Source

pub fn is_active(&self) -> bool

Returns whether the tween is currently running.

Source

pub fn is_completed(&self) -> bool

Returns whether the tween has completed.

Source

pub fn transition_to(&mut self, target: T)

Starts a transition from the current value to target.

Source

pub fn tick(&mut self, delta: impl Into<Duration>)

Advances the tween by delta.

Source

pub fn pause(&mut self)

Pauses the tween when it is running.

Source

pub fn resume(&mut self)

Resumes the tween when it is paused.

Source

pub fn cancel(&mut self)

Cancels the tween unless it is already completed or canceled.

Source

pub fn seek(&mut self, progress: f32)

Seeks to normalized progress within the complete timing interval.

Source

pub fn finish(&mut self)

Moves the tween to its final value and completed state.

Trait Implementations§

Source§

impl<T: Animatable> Animation<T> for Tween<T>

Source§

fn value(&self) -> &T

Returns the animation’s current value.
Source§

fn state(&self) -> AnimationState

Returns the animation’s lifecycle state.
Source§

fn duration(&self) -> Option<Duration>

Returns the total duration when it is finite and known.
Source§

fn tick(&mut self, delta: Duration)

Advances the animation by delta.
Source§

fn advance(&mut self, delta: Duration) -> Duration

Advances the animation and returns any unconsumed duration.
Source§

fn pause(&mut self)

Pauses a running animation.
Source§

fn resume(&mut self)

Resumes a paused animation.
Source§

fn cancel(&mut self)

Cancels the animation.
Source§

fn seek(&mut self, progress: f32)

Seeks to normalized progress within the animation.
Source§

fn finish(&mut self)

Moves the animation to its completed state.
Source§

fn retarget(&mut self, target: &T) -> bool

Attempts to continue the animation toward a new target. Read more
Source§

fn is_active(&self) -> bool

Returns whether the animation is currently running.
Source§

impl<T: Clone + Animatable> Clone for Tween<T>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Animatable> Debug for Tween<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for Tween<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Tween<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.

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.