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
impl Animation
Sourcepub fn timing<T>(
value: Animated<T>,
to: T,
ms: u32,
easing: Easing,
) -> Animationwhere
T: Lerp + 'static,
pub fn timing<T>(
value: Animated<T>,
to: T,
ms: u32,
easing: Easing,
) -> Animationwhere
T: Lerp + 'static,
Moves value to to over ms milliseconds along easing, from wherever it is when
the step starts.
Sourcepub fn tween<T>(value: Animated<T>, to: T, spec: AnimSpec) -> Animationwhere
T: Lerp + 'static,
pub fn tween<T>(value: Animated<T>, to: T, spec: AnimSpec) -> Animationwhere
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.
Sourcepub fn spring(value: Animated, to: f64, spring: Spring) -> Animation
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.
Sourcepub fn decay(value: Animated, decay: Decay) -> Animation
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.
Sourcepub fn drive(
spec: AnimSpec,
step: impl FnMut(AnimSample) + 'static,
) -> Animation
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.
Sourcepub fn sequence(steps: impl IntoIterator<Item = Animation>) -> Animation
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.
Sourcepub fn parallel(steps: impl IntoIterator<Item = Animation>) -> Animation
pub fn parallel(steps: impl IntoIterator<Item = Animation>) -> Animation
Runs steps together and ends with the last of them.
Sourcepub fn stagger(
gap_ms: u32,
steps: impl IntoIterator<Item = Animation>,
) -> Animation
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.
Sourcepub fn looped(self) -> Animation
pub fn looped(self) -> Animation
Plays the animation again each time it ends, until it is stopped.
Sourcepub fn is_endless(&self) -> bool
pub fn is_endless(&self) -> bool
Whether the animation never ends by itself.
Sourcepub fn jump_to_end(&self)
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.
Sourcepub fn start(&self) -> Playing ⓘ
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).
Sourcepub fn start_on(&self, clock: FrameClock) -> Playing ⓘ
pub fn start_on(&self, clock: FrameClock) -> Playing ⓘ
Plays the animation on clock’s frames.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Animation
impl !Send for Animation
impl !Sync for Animation
impl !UnwindSafe for Animation
impl Forget for Animation
impl Freeze for Animation
impl Move for Animation
impl Unpin for Animation
impl UnsafeUnpin for Animation
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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