Animate for callbacks

on_complete fires once. Callbacks can be used in a cycling animation.
This commit is contained in:
Jonathan Johnson 2024-09-22 10:41:30 -07:00
parent 3359fe0d05
commit 3c12363ec4
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 30 additions and 0 deletions

View file

@ -180,6 +180,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `PendingApp::with_tracing` and `PendingApp::initialize_tracing` install
Cushy's tracing Subscriber. The default `PendingApp` has tracing initialized,
but `PendingApp::new` does not.
- `Animate` and `IntoAnimate` are now implemented for:
- `impl FnMut(Duration) -> ControlFlow<Duration> + Send + Sync + 'static`
- `SharedCallback<Duration, ControlFlow<Duration>>`
- `SharedCallback`
[139]: https://github.com/khonsulabs/cushy/issues/139

View file

@ -821,6 +821,31 @@ impl Animate for SharedCallback<Duration, ControlFlow<Duration>> {
}
}
impl<F> IntoAnimate for F
where
F: FnMut(Duration) -> ControlFlow<Duration> + Send + Sync + 'static,
{
type Animate = Self;
fn into_animate(self) -> Self::Animate {
self
}
}
impl<F> Animate for F
where
F: FnMut(Duration) -> ControlFlow<Duration> + Send + Sync + 'static,
{
/// 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(elapsed)
}
}
/// Performs a linear interpolation between two values.
///
/// This trait can be derived for structs and fieldless enums.