pub struct Spring {
pub value: f32,
pub velocity: f32,
/* private fields */
}Expand description
A value that follows its target like a damped spring.
§Examples
use rust_glass::prelude::*;
let mut width = Spring::new(100.0);
// Called once per frame with the frame time.
let moving = width.step(240.0, Tuning::SMOOTH, 1.0 / 60.0);
assert!(moving && width.value > 100.0);Fields§
§value: f32Current value.
velocity: f32Current velocity, in units per second.
Implementations§
Source§impl Spring
impl Spring
Sourcepub fn step(&mut self, target: f32, tuning: Tuning, dt: f32) -> bool
pub fn step(&mut self, target: f32, tuning: Tuning, dt: f32) -> bool
Moves towards target by dt seconds and returns true while still
moving.
The first step of a Default spring jumps straight to the target,
so a widget never animates in from zero by accident.
The step uses the exact solution of the damped oscillator, so the result is the same at any frame rate and a long frame cannot make it unstable.
Trait Implementations§
impl Copy for Spring
impl StructuralPartialEq for Spring
Auto Trait Implementations§
impl Forget for Spring
impl Freeze for Spring
impl Move for Spring
impl RefUnwindSafe for Spring
impl Send for Spring
impl Sync for Spring
impl Unpin for Spring
impl UnsafeUnpin for Spring
impl UnwindSafe for Spring
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.