Skip to main content

Tween

Struct Tween 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§from: T

The value at the start.

§to: T

The value at the end.

§delay: u32

How long it holds from before its first play. 0 when left out.

§duration: u32

How long one play lasts.

§ease: E

Its curve. Ease::Linear when left out.

§repeat: Repeat

How many times it plays. Repeat::Once when left out.

§yoyo: bool

Whether 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> Tween<T>

Source

pub const fn new(from: T, to: T, duration: u32) -> Self

One play from from to to over duration, with no delay, along Ease::Linear.

Source

pub const fn with_ease<F>(self, ease: F) -> Tween<T, F>

It along ease: an Ease, or a curve of the game’s own.

Source§

impl<T: Copy, E: Copy> Tween<T, E>

The builders are const fns, so a game can keep a tween in a const. A const fn can’t drop a part of a type that may need dropping, so they ask for Copy: every Lerp type and every Ease is. A tween along a curve that isn’t Copy calls them before with_ease, or assigns its fields.

Source

pub const fn with_delay(self, delay: u32) -> Self

It after delay.

Source

pub const fn with_repeat(self, repeat: Repeat) -> Self

It played as repeat says.

Source

pub const fn with_yoyo(self, yoyo: bool) -> Self

It back and forth.

Source§

impl<T, E> Tween<T, E>

Source

pub const fn done_at(&self) -> Option<u32>

When its last play ends: delay + duration * plays, stopping at u32::MAX. None for Repeat::Loop.

Source

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>

Source

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.

Trait Implementations§

Source§

impl<T: Clone, E: Clone> Clone for Tween<T, E>

Source§

fn clone(&self) -> Tween<T, E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy, E: Copy> Copy for Tween<T, E>

Source§

impl<T: Debug, E: Debug> Debug for Tween<T, E>

Source§

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

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

impl<'de, T, E> Deserialize<'de> for Tween<T, E>
where T: Deserialize<'de>, E: Deserialize<'de> + Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Eq, E: Eq> Eq for Tween<T, E>

Source§

impl<T: PartialEq, E: PartialEq> PartialEq for Tween<T, E>

Source§

fn eq(&self, other: &Tween<T, E>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T, E> Serialize for Tween<T, E>
where T: Serialize, E: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq, E: PartialEq> StructuralPartialEq for Tween<T, E>

Auto Trait Implementations§

§

impl<T, E> Freeze for Tween<T, E>
where T: Freeze, E: Freeze,

§

impl<T, E> RefUnwindSafe for Tween<T, E>

§

impl<T, E> Send for Tween<T, E>
where T: Send, E: Send,

§

impl<T, E> Sync for Tween<T, E>
where T: Sync, E: Sync,

§

impl<T, E> Unpin for Tween<T, E>
where T: Unpin, E: Unpin,

§

impl<T, E> UnsafeUnpin for Tween<T, E>
where T: UnsafeUnpin, E: UnsafeUnpin,

§

impl<T, E> UnwindSafe for Tween<T, E>
where T: UnwindSafe, E: UnwindSafe,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.