pub enum TimingFunction {
Linear,
EaseIn,
EaseOut,
EaseInOut,
CubicBezier(f32, f32, f32, f32),
Spring(SpringConfig),
Custom(CustomCurve),
}Expand description
Timing function that controls the animation curve
Variants§
Linear
Linear interpolation (constant speed)
EaseIn
Starts slow, ends fast
EaseOut
Starts fast, ends slow
EaseInOut
Starts slow, speeds up, then slows down
CubicBezier(f32, f32, f32, f32)
CSS cubic-bezier curve (x1, y1, x2, y2)
Spring(SpringConfig)
Spring physics simulation (can overshoot)
Custom(CustomCurve)
A curve of the caller’s own, built by custom.
The excursion it carries is sampled once at construction rather than the
curve being clamped to a constant: anything sizing a bound from a curve —
a damage rect is why this exists — needs a number that is true of that
curve, and a hand-rolled bounce should bounce as far as it was written
to. Which is why CustomCurve cannot be assembled by hand: a
Custom(f, 0.0) written out where the enum is in scope type-checks, and
its excursion is then a claim nobody measured.
Implementations§
Source§impl TimingFunction
impl TimingFunction
Sourcepub fn evaluate(&self, t: f32) -> f32
pub fn evaluate(&self, t: f32) -> f32
Evaluate the timing function at time t (0.0 to 1.0) Returns the interpolation factor (can exceed [0, 1] for overshoot)
Note: Spring animations are handled separately in AnimationState::advance() using real elapsed time. This method returns t as fallback for springs.
Sourcepub fn peak_overshoot(&self) -> f32
pub fn peak_overshoot(&self) -> f32
How far past 1.0 this curve can go, as a fraction of the distance travelled. Zero for every curve that only eases.
A bezier is bounded by its control polygon, so its control points give the bound directly, and a spring’s physics give it exactly.
A Custom curve is an arbitrary closure, so it
cannot be asked — it is measured:
custom samples it once when it is built and
carries the excursion it found, which is what this reports. The curve
itself is untouched, and evaluate hands back exactly
what it returns.
Clamping the curve to an assumed allowance would make the bound true by shortening every hand-rolled bounce, silently, which is the wrong way round: the bound describes the curve, not the reverse. Assuming one without measuring is no better — a bounce peaking at 1.5 would have had its damage rect measured for 1.25, leaving the ring between the two outside every one of them.
Sourcepub fn custom<F>(f: F) -> Self
pub fn custom<F>(f: F) -> Self
Create a custom timing function from a closure.
The curve is sampled here, once, to find how far it leaves [0, 1] — so
building one costs a construction plus 65 evaluations of
the closure, around half a microsecond for a curve with a trig call in
it. Free where a curve is built once and shared, which is the usual
shape; inside a per-row builder rebuilt on every pass it is worth
hoisting, since TimingFunction is Clone.
Trait Implementations§
Source§impl Clone for TimingFunction
impl Clone for TimingFunction
Auto Trait Implementations§
impl !RefUnwindSafe for TimingFunction
impl !UnwindSafe for TimingFunction
impl Freeze for TimingFunction
impl Send for TimingFunction
impl Sync for TimingFunction
impl Unpin for TimingFunction
impl UnsafeUnpin for TimingFunction
Blanket Implementations§
Source§impl<T, M, S> Animate<T, M> for Swhere
T: Clone + 'static,
S: IntoSignal<T, M>,
impl<T, M, S> Animate<T, M> for Swhere
T: Clone + 'static,
S: IntoSignal<T, M>,
Source§fn transition(self, transition: impl Into<TransitionConfig>) -> Animated<T>
fn transition(self, transition: impl Into<TransitionConfig>) -> Animated<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.