Struct Tween

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

A one-shot eased transition from from to to over duration seconds, optionally after a delay. Non-finite or negative timesteps count as zero; a nonpositive duration finishes immediately.

use ferravex_play::tween::{Ease, Motion, Tween};
let mut slide = Tween::new(-40., 0., 0.4, Ease::BackOut).delayed(0.1);
assert_eq!(slide.advance(0.1, Motion::Full), -40.); // still delayed
slide.advance(0.2, Motion::Full);
assert!(slide.value() > -40. && !slide.is_finished());
slide.advance(1., Motion::Full);
assert_eq!(slide.value(), 0.);
slide.retarget(100.); // continue smoothly from the current value
assert_eq!(Tween::new(0., 5., 1., Ease::Linear).advance(0.01, Motion::Reduced), 5.);

Implementations§

Source§

impl Tween

Source

pub fn new(from: f32, to: f32, duration: f32, ease: Ease) -> Tween

Source

pub fn settled(value: f32) -> Tween

A tween that already sits at value.

Source

pub fn delayed(self, delay: f32) -> Tween

Waits delay seconds before starting.

Source

pub fn advance(&mut self, dt: f32, motion: Motion) -> f32

Advances time and returns the new value. Reduced motion jumps to the end.

Source

pub fn progress(&self) -> f32

Linear progress in [0, 1], excluding the delay.

Source

pub fn value(&self) -> f32

Current eased value; exactly to once finished.

Source

pub fn target(&self) -> f32

Source

pub fn is_finished(&self) -> bool

Source

pub fn finish(&mut self)

Jumps to the end.

Source

pub fn restart(&mut self)

Restarts from from (keeping duration, delay and easing).

Source

pub fn retarget(&mut self, to: f32)

Starts a new tween from the current value toward to without a delay.

Trait Implementations§

Source§

impl Clone for Tween

Source§

fn clone(&self) -> Tween

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Tween

Source§

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

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

impl PartialEq for Tween

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Tween

Source§

impl StructuralPartialEq for Tween

Auto Trait Implementations§

§

impl Freeze for Tween

§

impl RefUnwindSafe for Tween

§

impl Send for Tween

§

impl Sync for Tween

§

impl Unpin for Tween

§

impl UnwindSafe for Tween

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> 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.