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 is a no-op; next_deadline returns None. On
transition back to active, each animation’s start_time is
rebased by the paused duration so the eased phase t is
continuous — a 50%-through sweep resumes at 50%, not snapped to
some other spot on the curve.
pub fn is_window_active(&self) -> bool
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()).
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:
stored AND the window is active. Used by the idle-work predicates
so a window-paused scheduler doesn’t keep the event loop in
ControlFlow::WaitUntil.
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 the scheduler is window-paused, all
(looping) animations are hidden, or there are no animations at
all. One-shot tweens are NOT visibility-gated — see the
matching note on tick.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active animations (for testing/debugging).