Skip to main content

Animated

Struct Animated 

Source
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,

Source

pub fn new(initial: T) -> Animated<T>

A value at rest on initial, animating on the current page’s window.

Source

pub fn on(clock: FrameClock, initial: T) -> Animated<T>

A value at rest on initial, animating on clock’s window.

Source

pub fn get(self) -> T

The value on screen now; tracked.

Source

pub fn get_untracked(self) -> T

The value on screen now, without subscribing.

Source

pub fn target(self) -> T

Where the value is headed (the value itself once it has arrived).

Source

pub fn is_animating(self) -> bool

Whether an animation is moving the value; tracked, so a control can disable itself while it is.

Source

pub fn set(self, value: T)

Puts the value at rest on value, taking it from any animation moving it.

Source

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.

Source

pub fn interpolate<U, const N: usize>( self, input: [f64; N], output: [U; N], ) -> impl Fn() + Clone + 'static
where U: Lerp + 'static, T: Into<f64>,

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]));
Source

pub fn interpolate_with<U>( self, map: Interpolation<U>, ) -> impl Fn() + Clone + 'static
where U: Lerp + 'static, T: Into<f64>,

A reactive read of the value mapped through map, for a map that extends past its ends or is shared.

Source§

impl Animated

Source

pub fn velocity(self) -> f64

The value’s speed in units per second; tracked. A spring and a decay start from it.

Source

pub fn set_velocity(self, velocity: f64)

Gives the value a speed without moving it: the velocity a finger released it with, before a spring or a decay takes it on.

Trait Implementations§

Source§

impl<T> Clone for Animated<T>
where T: Lerp + 'static,

Source§

fn clone(&self) -> Animated<T>

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
Source§

impl<T> Copy for Animated<T>
where T: Lerp + 'static,

Source§

impl<T> Debug for Animated<T>
where T: Lerp + Debug + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl IntoReactive<Ink, IntoMark<Animated<Color>>> for Animated<Color>

An animated color goes wherever an ink or a paint does: .background(fade).

Source§

impl IntoReactive<Paint, IntoMark<Animated<Color>>> for Animated<Color>

Source§

impl IntoReactive<Paint, IntoMark<Animated<Ink>>> for Animated<Ink>

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).

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>
where Signal<T>: Freeze, Signal<Slot<T>>: Freeze,

§

impl<T> Move for Animated<T>

§

impl<T> Unpin for Animated<T>
where Signal<T>: Unpin, Signal<Slot<T>>: Unpin,

§

impl<T> UnsafeUnpin for Animated<T>
where Signal<T>: UnsafeUnpin, Signal<Slot<T>>: UnsafeUnpin,

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.