Skip to main content

Curve

Enum Curve 

Source
pub enum Curve {
    Spring(Spring),
    Tween {
        duration: f32,
        easing: Easing,
    },
    Decay {
        k: f32,
    },
    Instant,
}
Expand description

How a value moves to its target. Every curve starts from the value’s current position and velocity, so a retarget mid-flight never jumps or snaps its speed.

Variants§

§

Spring(Spring)

A spring (the default for interface motion).

§

Tween

A timed curve: duration seconds along easing. A starting velocity fades out over the duration, so it is kept at the start and the value still lands at duration.

Fields

§duration: f32

Seconds; 0 or less jumps, NaN is 0.3, capped at 60.

§easing: Easing

The easing curve.

§

Decay

Momentum: the value coasts on its velocity and slows at k per second, resting at x + v / k. The target is ignored (see gesture::project for where it rests).

Fields

§k: f32

Deceleration rate per second, clamped to 0.05..=1000 (NaN is 2, about a normal scroll).

§

Instant

Jump to the target.

Implementations§

Source§

impl Curve

Source

pub const DEFAULT: Curve

Source

pub const fn tween(duration: f32, easing: Easing) -> Curve

A tween of duration seconds (sanitised like the field docs say).

Source

pub fn decay(rate_per_ms: f32) -> Curve

Momentum with a per-millisecond deceleration rate (0.998 normal, 0.99 fast; see gesture::deceleration).

Source

pub const fn sanitized(self) -> Curve

The same curve with its public fields in range: a zero-length tween or spring becomes Curve::Instant.

Source

pub const fn is_instant(self) -> bool

Whether the value jumps.

Source

pub fn rest(self, x0: f32, v0: f32, target: f32) -> f32

Where a motion from (x0, v0) toward target comes to rest: the target, or for Curve::Decay the projected point x0 + v0 / k.

Source

pub fn sample(self, x0: f32, v0: f32, target: f32, t: f32) -> (f32, f32)

Position and velocity t seconds into a motion from (x0, v0) toward target. Always finite; t ≤ 0 (or NaN) is the start.

Source

pub fn settle_time(self, x0: f32, v0: f32, target: f32, eps: Eps) -> f32

Seconds until a motion from (x0, v0) toward target stays within eps for good (the duration for a tween, 0 for instant, at most MAX_SETTLE).

Source

pub fn settle_time_lanes( self, lanes: impl IntoIterator<Item = (f32, f32, f32)>, eps: Eps, ) -> f32

The settle time of several lanes (x0, v0, target) moving together along this curve: never earlier than any lane’s (see Spring::settle_time_lanes).

Trait Implementations§

Source§

impl Clone for Curve

Source§

fn clone(&self) -> Self

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 Copy for Curve

Source§

impl Debug for Curve

Source§

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

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

impl Default for Curve

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Spring> for Curve

Source§

fn from(s: Spring) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Curve

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Curve

Auto Trait Implementations§

§

impl Forget for Curve

§

impl Freeze for Curve

§

impl Move for Curve

§

impl RefUnwindSafe for Curve

§

impl Send for Curve

§

impl Sync for Curve

§

impl Unpin for Curve

§

impl UnsafeUnpin for Curve

§

impl UnwindSafe for Curve

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