SharedCallback animation

This commit is contained in:
Jonathan Johnson 2024-09-22 10:38:46 -07:00
parent fb1888d53f
commit 3359fe0d05
No known key found for this signature in database
GPG key ID: A66D6A34D6620579

View file

@ -58,6 +58,7 @@ use crate::animation::easings::Linear;
use crate::styles::{Component, RequireInvalidation};
use crate::utils::run_in_bg;
use crate::value::{Destination, Dynamic, Source};
use crate::widget::SharedCallback;
use crate::Cushy;
static ANIMATIONS: Mutex<Animating> = Mutex::new(Animating::new());
@ -778,6 +779,48 @@ impl Animate for Duration {
}
}
impl IntoAnimate for SharedCallback {
type Animate = Self;
/// Invokes this callback when the animation progresses. Consumes no
/// animation time.
fn into_animate(self) -> Self::Animate {
self
}
}
impl Animate for SharedCallback {
/// Invokes the callback and consumes no animation time.
fn animate(&mut self, elapsed: Duration) -> ControlFlow<Duration> {
self.invoke(());
ControlFlow::Break(elapsed)
}
}
impl IntoAnimate for SharedCallback<Duration, ControlFlow<Duration>> {
type Animate = Self;
/// Invokes this callback to implement a custom animation.
///
/// Returning `ControlFlow::Continue` consumes the entire elapsed duration.
/// Returning `ControlFlow::Break` completes the animation and yields the
/// provided duration to the next animation.
fn into_animate(self) -> Self::Animate {
self
}
}
impl Animate for SharedCallback<Duration, ControlFlow<Duration>> {
/// Invokes this callback to implement a custom animation.
///
/// Returning `ControlFlow::Continue` consumes the entire elapsed duration.
/// Returning `ControlFlow::Break` completes the animation and yields the
/// provided duration to the next animation.
fn animate(&mut self, elapsed: Duration) -> ControlFlow<Duration> {
self.invoke(elapsed)
}
}
/// Performs a linear interpolation between two values.
///
/// This trait can be derived for structs and fieldless enums.