1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Frame-driving hook for the continuous animation engine.
//!
//! The animation engine (`whisker-animation`) is a *separate* crate
//! that depends on this one — so this runtime crate cannot name its
//! `AnimationScheduler` directly (that would be a dependency cycle).
//! Instead the runtime exposes a tiny inversion-of-control surface:
//!
//! - The engine registers a **per-frame step callback** via
//! [`set_step_callback`]. The callback advances every active
//! controller by the elapsed wall-clock time and returns whether
//! *any* controller is still animating.
//! - Each frame, the driver's `tick_frame` calls [`step`], which
//! invokes the registered callback and latches its "still animating"
//! result into a thread-local flag.
//! - [`is_animating`] reports that flag. The reactive scheduler's
//! [`has_pending_work`](crate::reactive::has_pending_work) ORs it in,
//! so the host keeps its vsync loop running while an animation is in
//! flight and releases it the moment the last controller finishes —
//! matching the runtime's level-triggered idle model.
//!
//! This keeps the runtime ignorant of *how* animation works (curves,
//! tweens, springs) while still owning the one thing only it can own:
//! the decision to keep ticking. Engine logic, types, and tests all
//! live in `whisker-animation`.
//!
//! Single-threaded, like the rest of the UI runtime: the active execution slot
//! is thread-local, while `RuntimeContext` retains one isolated animation state
//! per mounted instance between Host callbacks.
use RefCell;
/// Signature of the engine's per-frame advance callback.
///
/// Receives the current monotonic timestamp in **milliseconds**
/// (injectable for tests; the driver feeds it a real monotonic clock).
/// Returns `true` if at least one controller is still animating after
/// this step — i.e. the host should schedule another frame.
pub type StepCallback = ;
pub
thread_local!
/// Register the engine's per-frame step callback. Called once by
/// `whisker-animation` when its scheduler is first touched on this
/// thread. Passing a new callback replaces any previous one.
/// Advance the animation engine by one frame at monotonic time
/// `now_ms` (milliseconds). Invokes the registered step callback (if
/// any) and latches whether anything is still animating.
///
/// Called once per frame from the driver's `tick_frame`. A no-op (and
/// clears the animating flag) when no engine is registered.
/// Whether any controller was still animating as of the last [`step`].
///
/// `has_pending_work()` ORs this in so the host keeps ticking while an
/// animation is in flight.
/// Directly set the animating flag. The engine calls this when a
/// controller is registered *between* frames (e.g. `forward()` from an
/// event handler) so `has_pending_work()` reports busy immediately —
/// before the next `step` has run — and the host wakes for a frame.
pub
/// (Test only) clear the registered callback and animating flag.