Expand description
Animation callbacks: event hooks at animation milestones.
Callbacks wraps any Animation and tracks milestone events
(start, completion, progress thresholds) that can be polled via
drain_events.
§Usage
ⓘ
use std::time::Duration;
use ftui_core::animation::{Fade, callbacks::{Callbacks, AnimationEvent}};
let mut anim = Callbacks::new(Fade::new(Duration::from_millis(500)))
.on_start()
.on_complete()
.at_progress(0.5);
anim.tick(Duration::from_millis(300));
for event in anim.drain_events() {
match event {
AnimationEvent::Started => { /* ... */ }
AnimationEvent::Progress(pct) => { /* crossed 50% */ }
AnimationEvent::Completed => { /* ... */ }
_ => {}
}
}§Design
Events are collected into an internal queue during tick() and drained
by the caller. This avoids closures/callbacks (which don’t compose well
in Elm architectures) and keeps the API pure.
§Invariants
Startedfires at most once per play-through (after firsttick()).Completedfires at most once (whenis_complete()transitions to true).- Progress thresholds fire at most once each, in ascending order.
drain_events()clears the queue — events are not replayed.reset()resets all tracking state so events can fire again.
§Failure Modes
- Threshold out of range (< 0 or > 1): clamped to [0.0, 1.0].
- Duplicate thresholds: each fires independently.
Structs§
- Callbacks
- An animation wrapper that emits events at milestones.
Enums§
- Animation
Event - An event emitted by a
Callbacks-wrapped animation.