Skip to main content

MotionTokens

Struct MotionTokens 

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

The application-global motion policy: every duration, stagger beat, and spring response the crate animates with, resolved through one value.

crate::init installs MotionTokens::DEFAULT unless the application already chose. To customize, build from default() and set the result — before windows render, so no frame is timed under two policies:

gpui_ai::init(cx);
gpui_ai::motion::MotionTokens::default()
    .with_quick(Duration::from_millis(120))
    .set(cx);

Components use the quick role for acknowledgments, standard for entrances and compact disclosures, and spring roles for bounded retargets. Named repeating effects keep their individual tempos. The deliberate role is available for application composition without adding motion implicitly.

What the policy cannot do: override reduced motion. cx.reduce_motion() stays authoritative in every consumer, so customization tunes tempo and feel, never whether travel happens for someone who asked for stillness.

Implementations§

Source§

impl MotionTokens

Source

pub const DEFAULT: Self

The crate’s default duration, spring, and repeating-effect policy.

Source

pub fn read(cx: &App) -> &Self

The policy the application installed, or the crate’s default where it installed none. Never panics: a window rendered before init runs is timed by Self::DEFAULT, the same values init would install.

Source

pub fn set(self, cx: &mut App)

Makes this policy the application’s, for every component at once.

Source

pub const fn instant(&self) -> Duration

Focus, press acknowledgement, pointer capture: zero, because a direct response to input is not eased.

Source

pub const fn quick(&self) -> Duration

Icon or label swap, copy acknowledgement, close.

Source

pub const fn hover_glide(&self) -> Duration

One hover highlight gliding between uniform rows, chasing the pointer on the strong ease-out. Faster than quick because the highlight follows input rather than acknowledging it; any reduced preference snaps the highlight instead.

Source

pub const fn standard(&self) -> Duration

Selected indicator, compact disclosure, progress retarget — and the crate’s entrance tempo.

Source

pub const fn deliberate(&self) -> Duration

Larger bounded panel or success choreography.

Restricted by contract to modal- and sheet-class surfaces and explanatory composition: nothing smaller — tooltips, popovers, dropdowns, toggles, row state — may bind to it, because 380ms on an element the reader is waiting on reads as lag, not weight. Popover-class entrances bind to quick.

Source

pub const fn press_spring(&self) -> SpringRole

Reversible control compression: fast and fully damped.

Source

pub const fn selection_spring(&self) -> SpringRole

An active pill or marker gliding between targets.

Source

pub const fn disclosure_spring(&self) -> SpringRole

Bounded panel geometry; no bounce, so it also suits destructive and error surfaces.

Source

pub const fn reflow_spring(&self) -> SpringRole

Visible row displacement: critically damped, velocity-preserving.

Source

pub const fn preference(&self) -> MotionPreference

The policy’s own motion preference, before the OS signal composes.

Source

pub fn effective_preference(cx: &App) -> MotionPreference

The preference actually in effect: the policy’s, floored at MotionPreference::Crossfade while the OS asks for reduced motion. Every clock, spring, and loop in the crate resolves through this.

Source

pub const fn with_preference(self, preference: MotionPreference) -> Self

Replaces the preference.

Source

pub const fn with_instant(self, duration: Duration) -> Self

Replaces the instant duration.

Source

pub const fn with_quick(self, duration: Duration) -> Self

Replaces the quick duration.

Source

pub const fn with_hover_glide(self, duration: Duration) -> Self

Replaces the hover_glide duration.

Source

pub const fn with_standard(self, duration: Duration) -> Self

Replaces the standard duration, which is also the entrance tempo every reveal in the crate settles at.

Source

pub const fn with_deliberate(self, duration: Duration) -> Self

Replaces the deliberate duration.

Source

pub const fn with_stagger_beat(self, beat: Duration) -> Self

Replaces the per-item stagger beat. The participation and aggregate caps are policy, not configuration, and stay where they are.

Source

pub const fn with_press_spring(self, response: Duration, damping: f32) -> Self

Replaces the press spring’s feel.

Source

pub const fn with_selection_spring( self, response: Duration, damping: f32, ) -> Self

Replaces the selection spring’s feel.

Source

pub const fn with_disclosure_spring( self, response: Duration, damping: f32, ) -> Self

Replaces the disclosure spring’s feel.

Source

pub const fn with_reflow_spring(self, response: Duration, damping: f32) -> Self

Replaces the reflow spring’s feel.

Source

pub fn arrival_stagger(&self, index: usize, arriving: usize) -> Duration

The delay item index of arriving newly visible items waits before its arrival plays — the stagger role.

The cascade decelerates: delays are spread with ease-out spacing, so later items land closer together and the group resolves quickly instead of trailing. At most six items take part, the whole cascade spends at most 220 ms, and items past the participation bound arrive with the last beat rather than after it — the bounded-choreography caps, which are policy rather than configuration. The per-item beat scales with with_stagger_beat.

Provisional like the other unconsumed roles: the motion lab is its first consumer and its validator, and the shipped reveal_staggered keeps its documented linear beats regardless.

Trait Implementations§

Source§

impl Clone for MotionTokens

Source§

fn clone(&self) -> MotionTokens

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 Debug for MotionTokens

Source§

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

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

impl Default for MotionTokens

Source§

fn default() -> Self

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

impl Global for MotionTokens

Source§

impl PartialEq for MotionTokens

Source§

fn eq(&self, other: &MotionTokens) -> 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 MotionTokens

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper.
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper.
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer.
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer.
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer.
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> ReadGlobal for T
where T: Global,

§

fn global(cx: &App) -> &T

Returns the global instance of the implementing type.
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.
§

impl<T> UpdateGlobal for T
where T: Global,

§

fn update_global<C, F, R>(cx: &mut C, update: F) -> R
where C: BorrowAppContext, F: FnOnce(&mut T, &mut C) -> R,

Updates the global instance of the implementing type using the provided closure.
§

fn set_global<C>(cx: &mut C, global: T)
where C: BorrowAppContext,

Set the global instance of the implementing type.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper.
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper.