pub struct AnimationScheduler { /* private fields */ }Expand description
Manages active animations and advances them each frame.
Implementations§
Source§impl AnimationScheduler
impl AnimationScheduler
pub fn new() -> Self
Sourcepub fn animate(
&mut self,
signal: &Signal<f32>,
widget_id: WidgetId,
target: f32,
duration: Duration,
easing: Easing,
now: Instant,
)
pub fn animate( &mut self, signal: &Signal<f32>, widget_id: WidgetId, target: f32, duration: Duration, easing: Easing, now: Instant, )
Start animating a Signal<f32> from its current value to target.
If the signal is already being animated, the previous animation is
replaced (the current in-flight value becomes the new start).
pub fn animate_with_options( &mut self, signal: &Signal<f32>, widget_id: WidgetId, target: f32, duration: Duration, easing: Easing, frame_interval: Option<Duration>, epsilon: f32, max_duration: Option<Duration>, now: Instant, )
Sourcepub fn animate_looping(
&mut self,
signal: &Signal<f32>,
widget_id: WidgetId,
start: f32,
end: f32,
period: Duration,
easing: Easing,
frame_interval: Option<Duration>,
epsilon: f32,
max_duration: Option<Duration>,
now: Instant,
)
pub fn animate_looping( &mut self, signal: &Signal<f32>, widget_id: WidgetId, start: f32, end: f32, period: Duration, easing: Easing, frame_interval: Option<Duration>, epsilon: f32, max_duration: Option<Duration>, now: Instant, )
Start a looping animation that cycles from start to end
repeatedly. The signal resets to start each time it reaches
end. Runs until cancelled.
Sourcepub fn cancel(&mut self, signal: &Signal<f32>)
pub fn cancel(&mut self, signal: &Signal<f32>)
Cancel any active animation on the given signal.
Sourcepub fn cancel_by_widget(&mut self, widget_id: WidgetId)
pub fn cancel_by_widget(&mut self, widget_id: WidgetId)
Cancel every animation whose driving widget matches widget_id.
Called when a widget is destroyed or rebuilt: the widget’s
Signal<f32> clones in the scheduler would otherwise outlive the
widget, continuing to tick against an orphaned signal whose
observers no longer exist — silent CPU waste and, on rebuild, a
second animation for the fresh signal stacking on top of the old.
Sourcepub fn set_window_active(&mut self, active: bool, now: Instant)
pub fn set_window_active(&mut self, active: bool, now: Instant)
Mark the owning window as active (focused-and-visible) or not.
Inactive: tick skips every looping animation and
next_deadline leaves them out. On transition back to active, each
looping animation’s start_time is rebased by the time it spent
paused so the eased phase t is continuous: a 50%-through sweep
resumes at 50%, not snapped to some other spot on the curve.
One-shot tweens run on. They are the same exception the
visibility gate in tick makes, for the same reason: a
tween is bounded by its own duration, so letting it finish costs a
handful of frames, while pausing it holds whatever it drives at an
arbitrary point. A Collapse opened while its window has no focus
(by an assistive technology, an automation client, or the app itself
in a window behind another) would otherwise keep its height at zero
until the window is focused again, with the disclosure already
reporting itself expanded.
pub fn is_window_active(&self) -> bool
Sourcepub fn rebase(&mut self, from: Instant, to: Instant)
pub fn rebase(&mut self, from: Instant, to: Instant)
Move every stored instant from one time axis onto another, preserving each animation’s elapsed time across the move.
Called when the tree switches the clock it measures animations against
— between the wall clock and its simulated one, in either direction.
Every instant this scheduler holds (start_time, next_tick,
started_at, and the pause mark) was taken on the axis that reads
from at this moment and has to be re-expressed on the one that reads
to, or the very next tick measures an elapsed time that includes the
whole gap between the two axes: forwards it completes every animation
at once, backwards it clamps every elapsed time to zero and nothing
moves again.
Shifting backwards past the underlying clock’s own origin is not
representable; such an instant is clamped to to, which costs that
animation its accumulated phase and nothing else. Reaching that clamp
takes a stored instant older than the platform’s monotonic origin, so it
is unreachable in practice and deliberately left untested.
Sourcepub fn tick(
&mut self,
now: Instant,
arena: &WidgetArena,
paint_epoch: u64,
) -> bool
pub fn tick( &mut self, now: Instant, arena: &WidgetArena, paint_epoch: u64, ) -> bool
Advance all active animations to the given time. Returns true if any animation is still running and eligible to run next tick (caller should request another frame).
arena + paint_epoch gate per-widget visibility for looping
animations only: a continuous spinner whose owner widget is
dormant or hasn’t been painted in the most recent paint pass
skips its tick. One-shot tweens are NOT visibility-gated — a
widget that animates its own size from zero (e.g. Collapse
growing from height=0 to natural) would otherwise be paused on
the very tick that would make it visible, locking it in the
invisible state forever. Pass paint_epoch == 0 to disable the
gate entirely (headless tests that never call render()).
The window-inactive pause is gated the same way: it holds looping
animations only (see set_window_active).
Sourcepub fn has_active(&self) -> bool
pub fn has_active(&self) -> bool
Whether any animation is currently stored in the scheduler
(ignores pause state — prefer has_running).
Sourcepub fn has_running(&self) -> bool
pub fn has_running(&self) -> bool
Whether any animation is eligible to advance on the next tick:
any one-shot tween, or any looping animation while the window is
active. Used by the idle-work predicates so a window-paused
scheduler doesn’t keep the event loop in ControlFlow::WaitUntil
for its loops, while a tween started in that window still finishes.
This does NOT check per-widget visibility (we’d need the arena
and the current paint epoch). An animation whose widget is
offscreen is still reported here; the per-widget gate lives in
next_deadline and tick directly.
Sourcepub fn next_deadline(
&self,
arena: &WidgetArena,
paint_epoch: u64,
) -> Option<Instant>
pub fn next_deadline( &self, arena: &WidgetArena, paint_epoch: u64, ) -> Option<Instant>
Earliest deadline at which a not-paused animation wants to
tick. Returns None when there are no animations at all, or when
every one left is a looping animation that is window-paused or
hidden. One-shot tweens are gated by neither: see the matching
notes on tick and
set_window_active.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active animations (for testing/debugging).