Skip to main content

Timeline

Struct Timeline 

Source
pub struct Timeline { /* private fields */ }
Expand description

A timeline that schedules multiple animations at specific offsets.

Implements Animation where value() returns overall progress (0.0–1.0).

Implementations§

Source§

impl Timeline

Source

pub fn new() -> Self

Create an empty timeline.

Source

pub fn add(self, offset: Duration, animation: impl Animation + 'static) -> Self

Add an animation event at an absolute offset (builder pattern).

Source

pub fn add_labeled( self, label: &str, offset: Duration, animation: impl Animation + 'static, ) -> Self

Add a labeled animation event at an absolute offset (builder pattern).

Source

pub fn then(self, animation: impl Animation + 'static) -> Self

Add an event relative to the last event’s offset (builder pattern).

If no events exist, the offset is 0.

Source

pub fn set_duration(self, d: Duration) -> Self

Set the total duration explicitly (builder pattern).

If not called, duration is inferred as max(event.offset). A zero duration is clamped to 1ns.

Source

pub fn set_loop_count(self, count: LoopCount) -> Self

Set the loop count (builder pattern).

Source§

impl Timeline

Source

pub fn play(&mut self)

Start or restart playback from the beginning.

Source

pub fn pause(&mut self)

Pause playback. No-op if not playing.

Source

pub fn resume(&mut self)

Resume from pause. No-op if not paused.

Source

pub fn stop(&mut self)

Stop playback and reset to idle.

Source

pub fn seek(&mut self, time: Duration)

Seek to an absolute time position.

Clamps to [0, total_duration]. Resets all animations and re-ticks them up to the seek point so their state is consistent.

Source

pub fn seek_label(&mut self, label: &str) -> bool

Seek to a labeled event’s offset.

Returns true if the label was found, false otherwise (no-op).

Source

pub fn progress(&self) -> f32

Current progress as a value in [0.0, 1.0].

Source

pub fn state(&self) -> PlaybackState

Current playback state.

Source

pub fn current_time(&self) -> Duration

Current time position.

Source

pub fn duration(&self) -> Duration

Total duration.

Source

pub fn event_count(&self) -> usize

Number of events in the timeline.

Source

pub fn event_value(&self, label: &str) -> Option<f32>

Get the animation value for a specific labeled event.

Returns None if the label doesn’t exist.

Source

pub fn event_value_at(&self, index: usize) -> Option<f32>

Get the animation value for an event by index.

Returns None if index is out of bounds.

Trait Implementations§

Source§

impl Animation for Timeline

Source§

fn tick(&mut self, dt: Duration)

Advance the animation by dt.
Source§

fn is_complete(&self) -> bool

Whether the animation has reached its end.
Source§

fn value(&self) -> f32

Current output value, clamped to [0.0, 1.0].
Source§

fn reset(&mut self)

Reset the animation to its initial state.
Source§

fn overshoot(&self) -> Duration

Time elapsed past completion. Used by composition types to forward remaining time (e.g., Sequence forwards overshoot from first to second). Returns Duration::ZERO for animations that never complete.
Source§

impl Debug for Timeline

Source§

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

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

impl Default for Timeline

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> 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, 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.