Skip to content

struct

Tween

pub struct Tween {
    pub props: Vec<Prop>,
    pub count: usize,
    pub duration: f64,
    pub delay: f64,
    pub ease: Ease,
    pub stagger: Option<Stagger>,
    pub repeat: i32,
    pub yoyo: bool,
    pub repeat_delay: f64,
    pub resolved: Vec<Vec<(String, String)>>,
}

A tween over count targets.

Fields

props

pub props: Vec<Prop>

The properties it animates.

count

pub count: usize

How many targets.

duration

pub duration: f64

Seconds each target takes.

delay

pub delay: f64

Seconds before it starts.

ease

pub ease: Ease

How it eases.

stagger

pub stagger: Option<Stagger>

How the targets' starts are spread.

repeat

pub repeat: i32

-1 repeats forever.

yoyo

pub yoyo: bool

Whether each repeat plays backwards from the last.

repeat_delay

pub repeat_delay: f64

Seconds between repeats.

resolved

pub resolved: Vec<Vec<(String, String)>>

Per-target (from, to) values once resolved by a runtime.

Methods

new

pub fn new(count: usize) -> Tween

A tween of count targets, with no properties yet, lasting half a second.

to

pub fn to(self, name: &str, value: impl ToString) -> Tween

Animate property name from where it is to value.

from

pub fn from(self, name: &str, value: impl ToString) -> Tween

Animate property name from value to where it is.

from_to

pub fn from_to(self, name: &str, from: impl ToString, to: impl ToString) -> Tween

Animate property name from from to to.

duration

pub fn duration(self, d: f64) -> Tween

How long it lasts, in seconds (at least 0).

delay

pub fn delay(self, d: f64) -> Tween

How long it waits before starting, in seconds.

ease

pub fn ease(self, e: Ease) -> Tween

Its easing.

stagger

pub fn stagger(self, s: Stagger) -> Tween

How its targets' starts are spread out.

repeat

pub fn repeat(self, n: i32, yoyo: bool) -> Tween

Play it n more times (-1 forever), going back and forth when yoyo.

target_duration

pub fn target_duration(&self) -> f64

One cycle plus repeats, for a single target (infinite if repeating forever).

total_duration

pub fn total_duration(&self) -> f64

Total length including delay and stagger.

progress

pub fn progress(&self, i: usize, t: f64) -> Option<f64>

Eased progress (0..=1) for target i at local time t, or None before it starts.

resolve

pub fn resolve(&mut self, current: impl Fn(usize, &str) -> String)

Fill in per-target start/end values, given each target's current value of a prop (current(target, prop)).

Trait implementations