mirror of
https://github.com/danbulant/cushy
synced 2026-07-07 04:00:45 +00:00
Animate for callbacks
on_complete fires once. Callbacks can be used in a cycling animation.
This commit is contained in:
parent
3359fe0d05
commit
3c12363ec4
2 changed files with 30 additions and 0 deletions
|
|
@ -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
|
- `PendingApp::with_tracing` and `PendingApp::initialize_tracing` install
|
||||||
Cushy's tracing Subscriber. The default `PendingApp` has tracing initialized,
|
Cushy's tracing Subscriber. The default `PendingApp` has tracing initialized,
|
||||||
but `PendingApp::new` does not.
|
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
|
[139]: https://github.com/khonsulabs/cushy/issues/139
|
||||||
|
|
|
||||||
|
|
@ -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.
|
/// Performs a linear interpolation between two values.
|
||||||
///
|
///
|
||||||
/// This trait can be derived for structs and fieldless enums.
|
/// This trait can be derived for structs and fieldless enums.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue