Skip to main content

AnimationTimer

Struct AnimationTimer 

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

Timer for tracking animation state.

Create once at the start of your animation and query it each frame to get the current animation state.

Implementations§

Source§

impl AnimationTimer

Source

pub fn new() -> Self

Create a new animation timer starting now.

Source

pub fn with_start(start: Instant) -> Self

Create a timer with a specific start time.

Source

pub fn elapsed(&self) -> Duration

Get elapsed time since timer started.

Source

pub fn elapsed_ms(&self) -> u128

Get elapsed time in milliseconds.

Source

pub fn reset(&mut self)

Reset the timer to now.

Returns true/false alternating at the given interval.

§Arguments
  • interval_ms - Time in milliseconds for each on/off phase
§Example
let visible = timer.blink(500); // Toggle every 500ms

Returns true/false with separate on and off durations.

§Arguments
  • on_ms - Time visible in milliseconds
  • off_ms - Time hidden in milliseconds
§Example
let visible = timer.blink_asymmetric(800, 200); // On 800ms, off 200ms
Source

pub fn cycle(&self, frame_count: usize, interval_ms: u64) -> usize

Cycle through N frames at the given interval.

§Arguments
  • frame_count - Number of frames to cycle through
  • interval_ms - Time per frame in milliseconds
§Returns

Frame index (0 to frame_count - 1)

§Example
let frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
let frame = timer.cycle(frames.len(), 80);
let spinner = frames[frame];
Source

pub fn progress(&self, duration_ms: u64, easing: Easing) -> f64

Get progress from 0.0 to 1.0 over the given duration.

§Arguments
  • duration_ms - Total duration in milliseconds
  • easing - Easing function to apply
§Returns

Progress value from 0.0 to 1.0, clamped at 1.0 after duration

§Example
let progress = timer.progress(1000, Easing::EaseInOut);
let width = (progress * max_width as f64) as usize;
Source

pub fn progress_loop(&self, duration_ms: u64, easing: Easing) -> f64

Get looping progress from 0.0 to 1.0, repeating.

§Arguments
  • duration_ms - Duration of one cycle in milliseconds
  • easing - Easing function to apply
§Example
let pulse = timer.progress_loop(1000, Easing::EaseInOut);
Source

pub fn progress_pingpong(&self, duration_ms: u64, easing: Easing) -> f64

Get ping-pong progress (0 -> 1 -> 0 -> 1…).

§Arguments
  • duration_ms - Duration of one direction (half cycle)
  • easing - Easing function to apply
§Example
let pulse = timer.progress_pingpong(500, Easing::EaseInOut);
// Goes 0->1 over 500ms, then 1->0 over 500ms, repeating
Source

pub fn is_elapsed(&self, duration_ms: u64) -> bool

Check if a duration has elapsed.

Trait Implementations§

Source§

impl Clone for AnimationTimer

Source§

fn clone(&self) -> AnimationTimer

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 Debug for AnimationTimer

Source§

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

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

impl Default for AnimationTimer

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