Skip to main content

Module motion

Module motion 

Source
Expand description

Motion primitives that respect the user’s reduced-motion preference.

The layers build on each other:

  • CubicBezier and Easing name curves;
  • Spring solves physical motion in closed form;
  • MotionSpec pairs a curve with a duration and delay;
  • Interpolate moves a value between two states;
  • Keyframes takes a value through named stops rather than straight across;
  • Transition animates a value whose target can change mid-flight, carrying the speed it already had across a retarget;
  • VelocityTracker measures how fast a gesture is moving, which is what flick, rubber_band and Transition::release need;
  • ScrollLink reads a scroll offset as a progress, which is motion with no clock in it at all;
  • Presence keeps an element alive long enough to animate out, and plays a phase backwards from where it had got to when the other cancels it;
  • Stagger spreads one specification across a group, forwards or in reverse;
  • Sequence runs specifications one after another and knows how long they take together;
  • Flipping::flip slides an element from where it was to where it is, and Flipping::flip_size additionally resizes it;
  • Animated::animate_in puts any of this on an element in one call, which is the layer most components should reach for.

Motion never changes what a surface publishes. A slide, a press response and a counting number are all painted over a layout, a hit target and a semantic tree that already report the settled value.

Decorative motion built on GPUI’s with_animation already stops when gpui::App::reduce_motion is set. Transition::animate and Presence::animate honor the same preference by finishing immediately.

Structs§

CubicBezier
A CSS-compatible cubic-bezier curve, evaluated in pure Rust so a curve can be asserted without a window.
Flip
A handle to one element’s slide, keyed by semantic id.
Flipped
An element painted at an offset from where layout put it, and optionally at a size on its way to the size layout would give it.
Keyframe
One stop on the path: the value, where along the run it is reached, and optionally the curve it is reached on.
Keyframes
A value that passes through named stops rather than travelling straight from one end to the other.
MotionSpec
A curve with a duration and a delay: everything one animation needs, taken from the token document rather than written beside the element.
Presence
An element’s arrival and departure, either of which can be cancelled by the other while it is still running.
ScrollLink
Scroll offsets mapped onto progress from 0 to 1.
Sequence
A chain of specifications, each starting when the one before it has finished.
Spring
A damped spring, solved in closed form so a position is a function of time rather than of how many frames happened to be delivered.
Stagger
Delays each item in a list so a group animates as a wave.
Transition
A value that animates toward whatever it is last told to be.
Velocity
How fast a gesture is moving, in pixels a second on each axis.
VelocityTracker
The speed and direction of a pointer, measured over a short trailing window.

Enums§

Activity
The shape of a piece of work that is currently under way.
Easing
A curve named by role rather than by control points.
Entrance
How an element arrives.
Flick
Which way a flick went.
Phase
Where an element is in its arrival or departure.

Constants§

ROW_STAGGER_CAP
The longest a row wave can last, whatever the row count.
VELOCITY_WINDOW
How far back a velocity is measured by default.

Traits§

Animated
A token-backed entrance in one call.
AnimationExt
An extension trait for adding the animation wrapper to both Elements and Components
Flipping
Slides an element from where it was to where it is.
Interpolate
A value an animation can move through.

Functions§

breathe
Breathes an element, for work that has nothing to report yet.
breathing_dot
A dot that breathes, for a place with room for a mark but not a glyph.
content_in
The arrival a block of content makes when it replaces what was there.
dialog
How a modal arrives: slower, because it is taking the page over.
dialog_arrival
How a modal arrives when it should arrive with weight: on the smooth spring, which keeps moving after a curve of the same length has stopped.
dialog_in
The arrival a modal makes: it rises onto the page on a spring, so it arrives with weight rather than simply appearing at full strength.
entrance
How a surface that is part of the page arrives.
fade_in
Fades element in over the entrance specification.
flick
Whether a gesture that travelled travel and let go at velocity was a flick, and which way it went.
flip
The slide handle for id.
gradient_opacity
The repeating opacity a gradient spinner turns on.
menu
How a menu opens: short, because it is answering a click.
menu_in
The opening a menu makes: a fade with a small rise.
pulse_wave
The repeating wave a loading placeholder breathes on.
reduce_motion
Whether the user asked for non-essential motion to be suppressed.
resize
How a value that has a position moves to a new one, such as a progress fill or an opening section.
row_in
The arrival one row of a menu-shaped list makes.
rubber_band
The distance actually shown when a gesture pulls overscroll past a boundary.
shared_flip
The slide handle for id, kept alive across a handoff between two element trees.
shimmer_offset
The sweep a loading placeholder’s highlight travels on, as a fraction of the placeholder’s own width.
spin
Turns a glyph, for work whose remaining extent is unknown.
staggered_phase
The repeating phase for item index in a looping group animation, such as a chase or wave loader.
state_change
How one control moves to a new state: short, because it is answering a pointer that is still on it.
sweep
A band travelling across whatever it is placed in, for work of known extent.
tracked_ids
The ids the flip global currently retains.
tracking
How a control that is being manipulated follows the value: the tight spring, so it feels attached rather than trailing.