pub struct Tween { /* private fields */ }Expand description
Linear interpolation between two values over a duration, with optional easing.
A Tween advances from from to to over duration_ticks render ticks.
Call Tween::value each frame with the current tick to get the
interpolated value. The tween is inactive until Tween::reset is called
with a start tick.
§Example
use slt::Tween;
use slt::anim::ease_out_quad;
let mut tween = Tween::new(0.0, 100.0, 20).easing(ease_out_quad);
tween.reset(0);
let v = tween.value(10); // roughly halfway, eased
assert!(v > 50.0); // ease-out is faster at the startImplementations§
Source§impl Tween
impl Tween
Sourcepub fn new(from: f64, to: f64, duration_ticks: u64) -> Self
pub fn new(from: f64, to: f64, duration_ticks: u64) -> Self
Create a new tween from from to to over duration_ticks ticks.
Uses linear easing by default. Call Tween::easing to change it.
The tween starts paused; call Tween::reset with the current tick
before reading values.
Sourcepub fn easing(self, f: fn(f64) -> f64) -> Self
pub fn easing(self, f: fn(f64) -> f64) -> Self
Set the easing function used to interpolate the value.
Any function with signature fn(f64) -> f64 that maps [0, 1] to
[0, 1] works. The nine built-in options are in this module.
Sourcepub fn on_complete(self, f: impl FnMut() + 'static) -> Self
pub fn on_complete(self, f: impl FnMut() + 'static) -> Self
Register a callback that runs once when the tween completes.
Auto Trait Implementations§
impl Freeze for Tween
impl !RefUnwindSafe for Tween
impl !Send for Tween
impl !Sync for Tween
impl Unpin for Tween
impl UnsafeUnpin for Tween
impl !UnwindSafe for Tween
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more