pub struct Animated<T = f64>where
T: Lerp + 'static,{ /* private fields */ }Expand description
A reactive value that animations move: a number with its velocity, or anything else with a
Lerp (a color, a point, a rect, a Vec of them).
Reading it is a tracked read, so whatever reads it follows the motion and nothing else re-runs. It goes straight into any modifier that takes a reactive value:
let fade = Animated::new(1.0);
let lift = Animated::new(0.0);
label(res::str::title())
.opacity(fade)
.translation(0.0, lift);
button(res::str::hide()).action(move || {
Animation::parallel([
Animation::timing(fade, 0.0, 220, Easing::EASE_IN_OUT),
Animation::spring(lift, -24.0, Spring::new(320.0, 22.0)),
])
.start();
});The value is Copy, like a Signal, and lives in the reactive scope it was made in: when
that scope is disposed, animations moving it stop.
One owner at a time: the latest animation step or set to touch a value
owns it, and an earlier step on the same value ends without moving it further. A spring
that takes over reads the velocity the displaced step left, which is what makes a retarget
bend the motion.
Implementations§
Source§impl<T> Animated<T>where
T: Lerp + 'static,
impl<T> Animated<T>where
T: Lerp + 'static,
Sourcepub fn new(initial: T) -> Animated<T>
pub fn new(initial: T) -> Animated<T>
A value at rest on initial, animating on the current page’s window.
Sourcepub fn on(clock: FrameClock, initial: T) -> Animated<T>
pub fn on(clock: FrameClock, initial: T) -> Animated<T>
A value at rest on initial, animating on clock’s window.
Sourcepub fn get_untracked(self) -> T
pub fn get_untracked(self) -> T
The value on screen now, without subscribing.
Sourcepub fn is_animating(self) -> bool
pub fn is_animating(self) -> bool
Whether an animation is moving the value; tracked, so a control can disable itself while it is.
Sourcepub fn set(self, value: T)
pub fn set(self, value: T)
Puts the value at rest on value, taking it from any animation moving it.
Sourcepub fn animate_to(self, target: T, spec: AnimSpec) -> Playing ⓘ
pub fn animate_to(self, target: T, spec: AnimSpec) -> Playing ⓘ
Animates from the value on screen to target under spec: its delay, curve or spring,
repeats and autoreverse, as AnimSpec::sample defines them. A call while an earlier
one is in flight starts from the value on screen, so the motion bends instead of
jumping. Shorthand for starting Animation::tween.
Sourcepub fn interpolate<U, const N: usize>(
self,
input: [f64; N],
output: [U; N],
) -> impl Fn() + Clone + 'static
pub fn interpolate<U, const N: usize>( self, input: [f64; N], output: [U; N], ) -> impl Fn() + Clone + 'static
A reactive read of the value mapped through input → output
(Interpolation), clamped at both ends: a closure for any modifier that takes a
reactive value. Colors blend in OKLab.
let scroll = Animated::new(0.0);
header
.opacity(scroll.interpolate([0.0, 120.0], [1.0, 0.0]))
.background(scroll.interpolate([0.0, 120.0], [Color::WHITE, accent]));Sourcepub fn interpolate_with<U>(
self,
map: Interpolation<U>,
) -> impl Fn() + Clone + 'static
pub fn interpolate_with<U>( self, map: Interpolation<U>, ) -> impl Fn() + Clone + 'static
A reactive read of the value mapped through map, for a map that extends past its
ends or is shared.
Trait Implementations§
impl<T> Copy for Animated<T>where
T: Lerp + 'static,
Source§impl IntoReactive<Ink, IntoMark<Animated<Color>>> for Animated<Color>
An animated color goes wherever an ink or a paint does: .background(fade).
impl IntoReactive<Ink, IntoMark<Animated<Color>>> for Animated<Color>
An animated color goes wherever an ink or a paint does: .background(fade).
fn into_reactive(self) -> Reactive<Ink>
Source§impl IntoReactive<Paint, IntoMark<Animated<Color>>> for Animated<Color>
impl IntoReactive<Paint, IntoMark<Animated<Color>>> for Animated<Color>
fn into_reactive(self) -> Reactive<Paint>
Source§impl IntoReactive<Paint, IntoMark<Animated<Ink>>> for Animated<Ink>
impl IntoReactive<Paint, IntoMark<Animated<Ink>>> for Animated<Ink>
fn into_reactive(self) -> Reactive<Paint>
Source§impl<T> IntoReactive<T, AnimatedMark> for Animated<T>where
T: Lerp + 'static,
An animated value (day::motion::Animated) is a reactive read of itself, so it goes
straight into .opacity(fade), .translation(0.0, lift) or .background(tint).
impl<T> IntoReactive<T, AnimatedMark> for Animated<T>where
T: Lerp + 'static,
An animated value (day::motion::Animated) is a reactive read of itself, so it goes
straight into .opacity(fade), .translation(0.0, lift) or .background(tint).
fn into_reactive(self) -> Reactive<T>
Auto Trait Implementations§
impl<T = f64> !RefUnwindSafe for Animated<T>
impl<T = f64> !Send for Animated<T>
impl<T = f64> !Sync for Animated<T>
impl<T = f64> !UnwindSafe for Animated<T>
impl<T> Forget for Animated<T>
impl<T> Freeze for Animated<T>
impl<T> Move for Animated<T>
impl<T> Unpin for Animated<T>
impl<T> UnsafeUnpin for Animated<T>
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