#[non_exhaustive]pub struct Tween<T, E = Ease> {
pub from: T,
pub to: T,
pub delay: u32,
pub duration: u32,
pub ease: E,
pub repeat: Repeat,
pub yoyo: bool,
}Expand description
A value going from from to to over duration, along a curve, after
delay: drawn from the time since it started alone
(value_at). The module docs say how a
simulation and a view keep one.
use shuyi_core::ease::Repeat;
use shuyi_core::{Ease, Tween};
// A title that bobs 2 cells up and down for ever, 500 ms each way.
const BOB: Tween<i32> = Tween::new(0, -2, 500)
.with_ease(Ease::Smooth)
.with_repeat(Repeat::Loop)
.with_yoyo(true);
assert_eq!(BOB.value_at(500), -2);
assert_eq!(BOB.value_at(1000), 0);
assert_eq!(BOB.value_at(1250), BOB.value_at(250));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.from: TThe value at the start.
to: TThe value at the end.
delay: u32How long it holds from before its first play. 0 when left out.
duration: u32How long one play lasts.
ease: EIts curve. Ease::Linear when left out.
repeat: RepeatHow many times it plays. Repeat::Once when left out.
yoyo: boolWhether every second play runs from to back to from, its time
backwards, as CSS’s alternate. false when left out.
Implementations§
Source§impl<T: Copy, E: Copy> Tween<T, E>
impl<T: Copy, E: Copy> Tween<T, E>
Sourcepub const fn with_delay(self, delay: u32) -> Self
pub const fn with_delay(self, delay: u32) -> Self
It after delay.
Sourcepub const fn with_repeat(self, repeat: Repeat) -> Self
pub const fn with_repeat(self, repeat: Repeat) -> Self
It played as repeat says.
Source§impl<T, E> Tween<T, E>
impl<T, E> Tween<T, E>
Sourcepub const fn done_at(&self) -> Option<u32>
pub const fn done_at(&self) -> Option<u32>
When its last play ends: delay + duration * plays, stopping at
u32::MAX. None for Repeat::Loop.
Sourcepub fn finished_between(&self, prev: u32, now: u32) -> bool
pub fn finished_between(&self, prev: u32, now: u32) -> bool
Whether it ended in the window after prev up to now: true when
prev < d <= now, d being done_at and at least
1, so a tween done at 0 ends in the first window that holds any time.
A screen or a simulation passes the previous frame’s or step’s time
and this one’s, starting from 0, and hears “it landed” once, with no
flag kept. Never true for Repeat::Loop.
Source§impl<T: Lerp, E: Easing> Tween<T, E>
impl<T: Lerp, E: Easing> Tween<T, E>
Sourcepub fn value_at(&self, t: u32) -> T
pub fn value_at(&self, t: u32) -> T
Its value t after it started: from before the delay, the eased
value during a play, and from done_at on the
value its last play ended on: for every Ease, to, or from
after an even number of plays with yoyo. With a duration of 0
it jumps to that value at the end of the delay; with
Repeat::Loop it then holds to.