mirror of
https://github.com/danbulant/cushy
synced 2026-06-18 05:51:20 +00:00
SharedCallback animation
This commit is contained in:
parent
fb1888d53f
commit
3359fe0d05
1 changed files with 43 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue