pub struct Spring<T>where
T: Animatable,{ /* private fields */ }Expand description
An animation driven by one or more damped spring channels.
Spring::new creates one channel and preserves the original behavior in
which every field shares the same physical progress. Use
Spring::with_channels when fields need different stiffness, damping, or
mass. Each channel produces a complete T; the compositor selects the
fields owned by each channel.
Channels use the analytic solution of the damped harmonic oscillator. Time is therefore not discarded for frame intervals greater than 100 ms, and simulation results are stable across different frame subdivisions.
§Examples
use aura_anim_core::{
Animation, Spring, SpringConfig,
timing::Duration,
};
let soft = SpringConfig::new(80.0, 18.0);
let snappy = SpringConfig::new(420.0, 28.0);
let mut spring = Spring::with_channels(
(0.0_f32, 0.0_f32),
(100.0, 1.0),
[soft, snappy],
|outputs| (outputs[0].0, outputs[1].1),
);
spring.tick(Duration::from_millis(100.0));
assert!(spring.value().1 > spring.value().0 / 100.0);Implementations§
Source§impl<T> Spring<T>where
T: Animatable,
impl<T> Spring<T>where
T: Animatable,
Sourcepub fn new(from: T, to: T, config: SpringConfig) -> Spring<T>
pub fn new(from: T, to: T, config: SpringConfig) -> Spring<T>
Creates a running spring animation with one physical channel.
All fields in T share this channel. For independently configured
fields, use Spring::with_channels.
Sourcepub fn with_channels(
from: T,
to: T,
configs: impl IntoIterator<Item = SpringConfig>,
compose: impl Fn(&[T]) -> T + 'static,
) -> Spring<T>
pub fn with_channels( from: T, to: T, configs: impl IntoIterator<Item = SpringConfig>, compose: impl Fn(&[T]) -> T + 'static, ) -> Spring<T>
Creates a running spring with independently configured channels.
Every channel evaluates the full transition from from to to with
its own physical state. compose must build the final value by
selecting the fields owned by each channel, in the same order as
configs.
An empty configuration iterator falls back to one default channel.
Sourcepub fn channel_count(&self) -> usize
pub fn channel_count(&self) -> usize
Returns the number of independently simulated physical channels.
Trait Implementations§
Source§impl<T> Animation<T> for Spring<T>where
T: Animatable,
impl<T> Animation<T> for Spring<T>where
T: Animatable,
Source§fn state(&self) -> AnimationState
fn state(&self) -> AnimationState
Source§fn retarget(&mut self, target: &T) -> bool
fn retarget(&mut self, target: &T) -> bool
Source§fn into_value(self: Box<Spring<T>>) -> T
fn into_value(self: Box<Spring<T>>) -> T
Source§fn duration(&self) -> Option<Duration>
fn duration(&self) -> Option<Duration>
Source§fn advance(&mut self, delta: Duration) -> Duration
fn advance(&mut self, delta: Duration) -> Duration
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Spring<T>
impl<T> !Send for Spring<T>
impl<T> !Sync for Spring<T>
impl<T> !UnwindSafe for Spring<T>
impl<T> Freeze for Spring<T>where
T: Freeze,
impl<T> Unpin for Spring<T>where
T: Unpin,
impl<T> UnsafeUnpin for Spring<T>where
T: UnsafeUnpin,
Blanket Implementations§
Source§impl<T, A> AnimationExt<T> for Awhere
T: Animatable,
A: Animation<T>,
impl<T, A> AnimationExt<T> for Awhere
T: Animatable,
A: Animation<T>,
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
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>
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>
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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.