pub struct AnimSpec {
pub duration_ms: u32,
pub delay_ms: u32,
pub curve: Curve,
pub repeat: u32,
pub autoreverse: bool,
}Expand description
Animation intent (§8.4): how a change to a native property is to be played. Threaded through
Toolkit::update/set_frame/set_opacity/set_transform; the toolkit plays it on its own
animator, and the frame-driven path (day::motion) samples the same function.
§The contract every toolkit keeps
A change from the value on screen (the start) to the new value (the target) plays as
follows, and AnimSpec::sample is that timeline as a function, so a toolkit with no
matching native feature drives the property from it and a test compares against it.
- Delay. For
delay_msthe property keeps showing the start value. The delay is served once, before the first cycle, never between repeats. - Cycle. One cycle lasts
duration_msand followscurvefrom the start to the target. A zero duration applies the target at once (after the delay). - Repeat. The cycle plays
repeat + 1times;u32::MAXrepeats until the property is next changed. Withoutautoreverseevery cycle starts again from the start value. - Autoreverse. With
autoreverseevery second cycle (the 2nd, 4th, …) plays the curve backwards, from the target to the start. - Rest. When a finite run ends the property rests on the target, whatever the last
cycle did. A run that ends on a backward cycle (autoreverse with an odd
repeat) is therefore followed by a jump to the target; use an evenrepeatto end on a forward one. - Spring. A
Curve::Springcycle is the spring’s closed-form response (Curve::fraction) forduration_ms, whichAnimSpec::springsets to the spring’s settle time, and it ends exactly on the cycle’s end value. - Retarget. A new change to a property in flight starts from the value on screen. A change with no animation cancels the run and applies at once.
What animates: frame, opacity, transform, and a container’s background color
(ContainerPatch::Background), whose in-between colors lie between the two ends in every
channel.
Fields§
§duration_ms: u32The length of one cycle, in milliseconds.
delay_ms: u32How long the start value is held before the first cycle, in milliseconds.
curve: CurveThe shape of one cycle.
repeat: u32Cycles beyond the first (0 = play once); u32::MAX = repeat forever.
autoreverse: boolWhether every second cycle plays backwards.
Implementations§
Source§impl AnimSpec
impl AnimSpec
Sourcepub const KEYFRAMES_PER_SECOND: f64 = 60.0
pub const KEYFRAMES_PER_SECOND: f64 = 60.0
How many keyframes AnimSpec::keyframes yields per second of cycle.
Sourcepub fn spring(response: f64, damping: f64) -> AnimSpec
pub fn spring(response: f64, damping: f64) -> AnimSpec
A spring: response is the period of its undamped oscillation in seconds, damping
its damping ratio (1.0 = no bounce, below 1.0 bouncy). duration_ms is the spring’s
settle time (Curve::settle_secs), so the cycle ends once the motion is too small to
see and a repeat or an autoreverse has a definite length.
Sourcepub fn ease_in_out(duration_ms: u32) -> AnimSpec
pub fn ease_in_out(duration_ms: u32) -> AnimSpec
Slow at both ends, over duration_ms.
Sourcepub fn repeat(self, count: u32, autoreverse: bool) -> AnimSpec
pub fn repeat(self, count: u32, autoreverse: bool) -> AnimSpec
Repeat count extra times (builder); autoreverse ping-pongs each cycle.
Sourcepub fn repeat_forever(self, autoreverse: bool) -> AnimSpec
pub fn repeat_forever(self, autoreverse: bool) -> AnimSpec
Repeat forever (builder), e.g. a pulsing indicator.
Sourcepub fn duration_secs(&self) -> f64
pub fn duration_secs(&self) -> f64
One cycle, in seconds.
Sourcepub fn delay_secs(&self) -> f64
pub fn delay_secs(&self) -> f64
The delay, in seconds.
Sourcepub fn repeats_forever(&self) -> bool
pub fn repeats_forever(&self) -> bool
Whether the spec repeats until the property is next changed.
Sourcepub fn cycles(&self) -> Option<u32>
pub fn cycles(&self) -> Option<u32>
How many cycles play, or None for a spec that repeats forever.
Sourcepub fn total_secs(&self) -> Option<f64>
pub fn total_secs(&self) -> Option<f64>
The whole run including the delay, in seconds, or None for a spec that repeats forever.
Sourcepub fn ends_reversed(&self) -> bool
pub fn ends_reversed(&self) -> bool
Whether a finite run’s last cycle plays backwards, ending on the start value before the property rests on its target (contract rule 5).
Sourcepub fn sample(&self, elapsed: f64) -> AnimSample
pub fn sample(&self, elapsed: f64) -> AnimSample
Where the run is elapsed seconds after the change was made: the contract above as a
function. During the delay the progress is 0; inside a cycle it is the curve, read
backwards on an autoreversed cycle; after the last cycle done is set and the progress
is where that cycle ended. The property itself rests on its target once done.
Sourcepub fn cycle_progress(&self, offset: f64) -> f64
pub fn cycle_progress(&self, offset: f64) -> f64
The progress at offset (0.0..=1.0) of one forward cycle. The cycle’s last point is
exactly 1, so a spring ends on its target instead of a residue away from it.
Sourcepub fn keyframes(&self) -> Vec<Keyframe>
pub fn keyframes(&self) -> Vec<Keyframe>
One forward cycle as evenly spaced keyframes, Self::KEYFRAMES_PER_SECOND of them per
second of cycle and never fewer than two: the first at offset 0 and progress 0, the last
at offset 1 and progress exactly 1. A toolkit without a spring animator plays these
through its keyframe animation or its custom interpolator with linear interpolation
between neighbors, which makes every toolkit draw the same spring. They serve the easing
curves equally, for a toolkit whose native curve of that name has another shape.
Trait Implementations§
impl Copy for AnimSpec
impl StructuralPartialEq for AnimSpec
Auto Trait Implementations§
impl Forget for AnimSpec
impl Freeze for AnimSpec
impl Move for AnimSpec
impl RefUnwindSafe for AnimSpec
impl Send for AnimSpec
impl Sync for AnimSpec
impl Unpin for AnimSpec
impl UnsafeUnpin for AnimSpec
impl UnwindSafe for AnimSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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