Skip to main content

Module callbacks

Module callbacks 

Source
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

  1. Started fires at most once per play-through (after first tick()).
  2. Completed fires at most once (when is_complete() transitions to true).
  3. Progress thresholds fire at most once each, in ascending order.
  4. drain_events() clears the queue — events are not replayed.
  5. 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§

AnimationEvent
An event emitted by a Callbacks-wrapped animation.