Easing
A timing curve: how the progress of an animation follows the progress of time, from 0.0 to
1.0. The same curves as CSS animation-timing-function.
Build one directly (linear, cubic_bezier,
steps) or read it from a CSS string, e.g. the easing a design tool exported
(parse: keywords, cubic-bezier(), steps() and linear()), then evaluate
it with at.
Import
Section titled “Import”Cargo feature animation (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”cubic_bezier
Section titled “cubic_bezier”The curve of CSS cubic-bezier(x1, y1, x2, y2). The y values may leave 0..=1 to
overshoot; the x values may not, as in CSS.
Parameters
| Parameter | Type | Description |
|---|---|---|
x1 | f64 | x of the first control point, 0.0..=1.0. |
y1 | f64 | y of the first control point. |
x2 | f64 | x of the second control point, 0.0..=1.0. |
y2 | f64 | y of the second control point. |
Returns
Option<Self> — The easing, or None when an x is outside 0.0..=1.0 or a value is not finite.
Examples
The curve of CSS steps(count, position): the progress moves by jumps instead of
continuously, for frame-by-frame sprites, ticking counters or an “instant” transition.
Parameters
| Parameter | Type | Description |
|---|---|---|
count | u32 | Number of steps, at least 1 (at least 2 with [StepPosition::JumpNone]). |
position | StepPosition | Where the jumps happen. |
Returns
Option<Self> — The easing, or None for a count that is too small.
Examples
Reads a CSS easing: linear, ease, ease-in, ease-out, ease-in-out, step-start,
step-end, cubic-bezier(x1, y1, x2, y2), steps(count[, position]) or
linear(0, 0.25 40%, 1) (points with optional input positions, which CSS fills in).
Case and extra spaces are ignored.
Parameters
| Parameter | Type | Description |
|---|---|---|
css | &str | The CSS easing. |
Returns
Result<Self, ParseEasingError> — The easing.
Errors
Returns a ParseEasingError for anything that is not a CSS easing, or a known function
with arguments CSS rejects.
Examples
The progress of the animation at a progress of time.
Parameters
| Parameter | Type | Description |
|---|---|---|
t | f64 | The progress of time. Clamped to 0.0..=1.0; a NaN counts as 0.0. |
Returns
f64 — The progress of the animation: 0.0 at the start and 1.0 at the end, possibly outside
0.0..=1.0 in between for curves that overshoot.
Examples
Error type: ParseEasingError
Section titled “Error type: ParseEasingError”Why a string is not a CSS easing.
