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
impl AnimationTimer
Sourcepub fn with_start(start: Instant) -> Self
pub fn with_start(start: Instant) -> Self
Create a timer with a specific start time.
Sourcepub fn elapsed_ms(&self) -> u128
pub fn elapsed_ms(&self) -> u128
Get elapsed time in milliseconds.
Sourcepub fn blink_asymmetric(&self, on_ms: u64, off_ms: u64) -> bool
pub fn blink_asymmetric(&self, on_ms: u64, off_ms: u64) -> bool
Sourcepub fn cycle(&self, frame_count: usize, interval_ms: u64) -> usize
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 throughinterval_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];Sourcepub fn progress(&self, duration_ms: u64, easing: Easing) -> f64
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 millisecondseasing- 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;Sourcepub fn progress_loop(&self, duration_ms: u64, easing: Easing) -> f64
pub fn progress_loop(&self, duration_ms: u64, easing: Easing) -> f64
Sourcepub fn progress_pingpong(&self, duration_ms: u64, easing: Easing) -> f64
pub fn progress_pingpong(&self, duration_ms: u64, easing: Easing) -> f64
Sourcepub fn is_elapsed(&self, duration_ms: u64) -> bool
pub fn is_elapsed(&self, duration_ms: u64) -> bool
Check if a duration has elapsed.
Trait Implementations§
Source§impl Clone for AnimationTimer
impl Clone for AnimationTimer
Source§fn clone(&self) -> AnimationTimer
fn clone(&self) -> AnimationTimer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AnimationTimer
impl Debug for AnimationTimer
Auto Trait Implementations§
impl Freeze for AnimationTimer
impl RefUnwindSafe for AnimationTimer
impl Send for AnimationTimer
impl Sync for AnimationTimer
impl Unpin for AnimationTimer
impl UnwindSafe for AnimationTimer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more