Skip to main content

KeyframeTrack

Struct KeyframeTrack 

Source
pub struct KeyframeTrack<T>
where T: Animatable,
{ pub looping: Loop, /* private fields */ }
Expand description

A sorted collection of keyframes that evaluates a value over time.

Empty tracks are valid. They evaluate to None instead of requiring T: Default or panicking.

§Example

use animato_core::{Easing, Update};
use animato_tween::KeyframeTrack;

let mut track = KeyframeTrack::new()
    .push_eased(0.0, 0.0_f32, Easing::EaseOutCubic)
    .push(1.0, 100.0);

track.update(0.5);
assert!(track.value().unwrap() > 50.0);

Fields§

§looping: Loop

Looping behavior for this track.

Implementations§

Source§

impl<T> KeyframeTrack<T>
where T: Animatable,

Source

pub fn new() -> KeyframeTrack<T>

Create an empty keyframe track.

Source

pub fn push(self, time: f32, value: T) -> KeyframeTrack<T>

Insert a linear keyframe and keep the track sorted by time.

If another frame already exists at the same time, it is replaced.

Source

pub fn push_eased(self, time: f32, value: T, easing: Easing) -> KeyframeTrack<T>

Insert a keyframe with an explicit segment easing.

If another frame already exists at the same time, it is replaced.

Source

pub fn looping(self, mode: Loop) -> KeyframeTrack<T>

Set the looping behavior.

Source

pub fn frames(&self) -> &[Keyframe<T>]

All frames in sorted order.

Source

pub fn elapsed(&self) -> f32

Current elapsed time in seconds.

Source

pub fn duration(&self) -> f32

Base duration in seconds, equal to the last keyframe time.

Source

pub fn progress(&self) -> f32

Normalized progress through the current finite playback span.

Source

pub fn value_at(&self, secs: f32) -> Option<T>

Evaluate the track at an absolute time in seconds.

Source

pub fn value(&self) -> Option<T>

Current value based on the track’s elapsed time.

Source

pub fn is_complete(&self) -> bool

true when the track has finished all finite playback.

Source

pub fn reset(&mut self)

Reset to the beginning of the track.

Trait Implementations§

Source§

impl<T> Clone for KeyframeTrack<T>
where T: Clone + Animatable,

Source§

fn clone(&self) -> KeyframeTrack<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 for KeyframeTrack<T>
where T: Debug + Animatable,

Source§

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

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

impl<T> Default for KeyframeTrack<T>
where T: Animatable,

Source§

fn default() -> KeyframeTrack<T>

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

impl<T> Playable for KeyframeTrack<T>
where T: Animatable,

Source§

fn duration(&self) -> f32

Total finite duration in seconds.
Source§

fn reset(&mut self)

Reset the animation to its initial state.
Source§

fn seek_to(&mut self, progress: f32)

Seek to normalized progress through the animation.
Source§

fn is_complete(&self) -> bool

true when the animation has reached its terminal state.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Return a type-erased shared reference for downcasting.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Return a type-erased mutable reference for downcasting.
Source§

impl<T> Update for KeyframeTrack<T>
where T: Animatable,

Source§

fn update(&mut self, dt: f32) -> bool

Advance the animation by dt seconds. Read more

Auto Trait Implementations§

§

impl<T> Freeze for KeyframeTrack<T>

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for KeyframeTrack<T>

§

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