pub struct Animations { /* private fields */ }Expand description
Registry/scheduler for running Tweens bound to apply callbacks.
Call tick once per [Event::Tick]
(crate::event::Event::Tick); it advances every entry by exactly one
tick, applies the sampled values, accumulates the dirty rects the
callbacks report (at most one per active animation per tick), and
auto-removes completed entries after their terminal value has been
applied — so a slide’s final frame lands exactly on its rest position.
Implementations§
Source§impl Animations
impl Animations
Sourcepub fn register(&mut self, tween: Tween, apply: ApplyFn) -> AnimId
pub fn register(&mut self, tween: Tween, apply: ApplyFn) -> AnimId
Register a tween bound to an apply callback. Returns the handle
for later cancel.
Sourcepub fn tick(&mut self) -> bool
pub fn tick(&mut self) -> bool
Advance all animations by one tick, apply their values, and drop
completed entries. Returns true while anything remains active.
The dirty rects reported by the apply callbacks during this tick
replace those of the previous tick — read them via
dirty_rects or
dirty_union before the next call.
Sourcepub fn any_active(&self) -> bool
pub fn any_active(&self) -> bool
Returns true while any animation is registered (a repaint is
pending). Does not advance state.
Sourcepub fn dirty_rects(&self) -> &[Rect]
pub fn dirty_rects(&self) -> &[Rect]
Dirty rects reported during the most recent tick,
one per animation whose callback returned a region. ANIM does not
merge or clip — feed these to the consumer’s planner.
Sourcepub fn dirty_union(&self) -> Option<Rect>
pub fn dirty_union(&self) -> Option<Rect>
Axis-aligned union of dirty_rects, or
None when the last tick changed nothing visible.
Sourcepub fn cancel(&mut self, id: AnimId) -> bool
pub fn cancel(&mut self, id: AnimId) -> bool
Remove an animation without applying a final value. Returns
true if the handle was registered.
Sourcepub fn pulse_color(
&mut self,
from: Color,
to: Color,
half_period: u32,
easing: Easing,
apply: Box<dyn FnMut(Color) -> Option<Rect>>,
) -> AnimId
pub fn pulse_color( &mut self, from: Color, to: Color, half_period: u32, easing: Easing, apply: Box<dyn FnMut(Color) -> Option<Rect>>, ) -> AnimId
Attention pulse: ping-pong a color between from and to with
half_period ticks per direction, forever (until cancelled).
apply receives the interpolated color each tick and returns the
invalidated region (typically the pulsing widget’s bounds).
Sourcepub fn slide_rect(
&mut self,
from: Rect,
to: Rect,
duration: u32,
easing: Easing,
apply: Box<dyn FnMut(Rect) -> Option<Rect>>,
) -> AnimId
pub fn slide_rect( &mut self, from: Rect, to: Rect, duration: u32, easing: Easing, apply: Box<dyn FnMut(Rect) -> Option<Rect>>, ) -> AnimId
Position slide: move a rect from from to to over duration
ticks, one-shot (show/hide of a container).
apply receives the interpolated rect each tick and returns the
invalidated region. The recommended dirty region is
previous_bounds.union(new_bounds) so both the vacated and the
newly covered pixels repaint.