Skip to main content

Animation

Struct Animation 

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

Motion for Animated values: one step, or a composition of several. Building one moves nothing; start plays it, and it can be started again.

ⓘ
let lifts: Vec<Animated> = (0..5).map(|_| Animated::new(0.0)).collect();
let entrance = Animation::stagger(
    70,
    lifts.iter().map(|&lift| {
        Animation::sequence([
            Animation::timing(lift, -46.0, 220, Easing::Power(Ease::Out, 2.0)),
            Animation::spring(lift, 0.0, Spring::new(320.0, 11.0)),
        ])
    }),
);
let playing = entrance.start();
day::task(async move {
    if playing.await == Outcome::Finished {
        status.set(Status::Arrived);
    }
});

Under reduced motion (reduce_motion) a finite animation puts every value on its end state at once, also when the setting flips mid-flight; one that never ends by itself (a looped pulse, the sign that work is going on) keeps running. An animation stops when a value it moves is disposed with its scope, so a page needs no cleanup of its own.

Implementations§

Source§

impl Animation

Source

pub fn timing<T>( value: Animated<T>, to: T, ms: u32, easing: Easing, ) -> Animation
where T: Lerp + 'static,

Moves value to to over ms milliseconds along easing, from wherever it is when the step starts.

Source

pub fn tween<T>(value: Animated<T>, to: T, spec: AnimSpec) -> Animation
where T: Lerp + 'static,

Moves value to to as spec says: its delay, its curve or spring, its repeats and autoreverse (AnimSpec::sample). The frame-driven twin of with_animation: a canvas value moved with the spec a native property is animated with moves in step with it. A spec that repeats forever never ends.

Source

pub fn spring(value: Animated, to: f64, spring: Spring) -> Animation

Springs value to to, starting at the velocity it has, until it comes to rest. A spring that takes over from another step, or follows set_velocity, carries that speed on.

Source

pub fn decay(value: Animated, decay: Decay) -> Animation

Lets value coast from the velocity it has until it stops, as a flung scroll view does.

Source

pub fn drive( spec: AnimSpec, step: impl FnMut(AnimSample) + 'static, ) -> Animation

Calls step with each frame’s AnimSample of spec, the last one done: for a transition that is more than one value (a chart blending two states). Under reduced motion step is called once, with the final sample.

Source

pub fn delay(ms: u32) -> Animation

Does nothing for ms milliseconds.

Source

pub fn sequence(steps: impl IntoIterator<Item = Animation>) -> Animation

Runs steps one after another. Each starts from where its value stands when its turn comes, and on the frame the step before it ends.

Source

pub fn parallel(steps: impl IntoIterator<Item = Animation>) -> Animation

Runs steps together and ends with the last of them.

Source

pub fn stagger( gap_ms: u32, steps: impl IntoIterator<Item = Animation>, ) -> Animation

Runs steps together, each starting gap_ms milliseconds after the one before it.

Source

pub fn repeat(self, times: u32) -> Animation

Plays the animation times times in a row.

Source

pub fn looped(self) -> Animation

Plays the animation again each time it ends, until it is stopped.

Source

pub fn is_endless(&self) -> bool

Whether the animation never ends by itself.

Source

pub fn jump_to_end(&self)

Puts every value where the animation would leave it, without playing it. An endless animation’s values are left where one pass would.

Source

pub fn start(&self) -> Playing ⓘ

Plays the animation on the window of the first value it moves (the current page’s window when it moves none).

Source

pub fn start_on(&self, clock: FrameClock) -> Playing ⓘ

Plays the animation on clock’s frames.

Trait Implementations§

Source§

impl Clone for Animation

Source§

fn clone(&self) -> Animation

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

Auto Trait Implementations§

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> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.