Skip to main content

Stagger

Struct Stagger 

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

Parallel staggered animation where each item starts after a fixed delay.

Stagger applies one tween configuration to many items. The start tick for each item is start_tick + delay_ticks * item_index.

By default the animation plays once (LoopMode::Once). Use Stagger::loop_mode to repeat or ping-pong. The total cycle length includes the delay of every item, so all items finish before the next cycle begins.

§Example

use slt::anim::{ease_out_quad, Stagger, LoopMode};

let mut stagger = Stagger::new(0.0, 100.0, 30)
    .easing(ease_out_quad)
    .delay(5)
    .loop_mode(LoopMode::Repeat);

stagger.reset(100);
let _ = stagger.value(120, 3);

Implementations§

Source§

impl Stagger

Source

pub fn new(from: f64, to: f64, duration_ticks: u64) -> Self

Create a new stagger animation template.

Uses linear easing, zero delay, and LoopMode::Once by default.

Source

pub fn easing(self, f: fn(f64) -> f64) -> Self

Set easing for each item’s tween.

Source

pub fn delay(self, ticks: u64) -> Self

Set delay in ticks between consecutive item starts.

Source

pub fn loop_mode(self, mode: LoopMode) -> Self

Set loop behavior. LoopMode::Repeat restarts after all items finish; LoopMode::PingPong reverses direction each cycle.

Source

pub fn items(self, count: usize) -> Self

Set the number of items for cycle length calculation.

When using LoopMode::Repeat or LoopMode::PingPong, the total cycle length is duration_ticks + delay_ticks * (item_count - 1). If not set, it is inferred from the highest item_index seen.

Source

pub fn value(&mut self, tick: u64, item_index: usize) -> f64

Return the value for item_index at tick.

Source

pub fn is_done(&self) -> bool

Returns true if the most recently sampled item reached its end value.

Source

pub fn reset(&mut self, tick: u64)

Restart stagger timing, treating tick as the base start time.

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.