pub struct Timers { /* private fields */ }Expand description
Registry/scheduler for tick-driven callbacks.
Call tick once per Event::Tick
dispatch. Entries advance in registration order; multiple entries may fire
in the same tick.
§no_std + alloc
Timers requires alloc (for Box<dyn FnMut> callbacks), consistent with
the ANIM-00 Animations registry.
Implementations§
Source§impl Timers
impl Timers
Sourcepub fn add(
&mut self,
period: u32,
repeat: TimerRepeat,
callback: Box<dyn FnMut(&TimerContext)>,
) -> TimerId
pub fn add( &mut self, period: u32, repeat: TimerRepeat, callback: Box<dyn FnMut(&TimerContext)>, ) -> TimerId
Register a repeating timer.
period is in ticks. The first fire occurs after period ticks.
repeat controls how many times it fires before exhaustion. Returns an
opaque TimerId for later control operations.
Sourcepub fn add_once(
&mut self,
period: u32,
callback: Box<dyn FnMut(&TimerContext)>,
) -> TimerId
pub fn add_once( &mut self, period: u32, callback: Box<dyn FnMut(&TimerContext)>, ) -> TimerId
Register a one-shot timer (convenience wrapper).
Equivalent to add(period, TimerRepeat::Remaining(1), callback) with
auto_delete = true. The entry is automatically removed after the
single fire. Used for delayed single actions (auto-close toast,
delayed start, etc.) as specified by LPAR-06 §5.7.
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Advance all non-paused timers by exactly one tick.
For each non-paused entry:
- If
readyis set, the entry fires immediately (countdown is not decremented — the next fire after a ready-fire is stillperiodticks from that point). - Otherwise,
countdownis decremented. When it reaches zero, the entry fires.
Firing order within a single tick is registration order (deterministic).
After firing, countdown is reset to period. If the repeat is
Remaining(n), it decrements to Remaining(n-1). When exhausted
(Remaining(0) becomes 0 after decrement), the entry is auto-deleted
(if auto_delete) or paused.
Sourcepub fn pause(&mut self, id: TimerId)
pub fn pause(&mut self, id: TimerId)
Pause a timer, freezing its countdown.
A paused timer is not advanced by tick. Pause/resume
does NOT reset the countdown; a timer paused mid-period resumes from
where it left off. Mirrors lv_timer_pause.
Sourcepub fn resume(&mut self, id: TimerId)
pub fn resume(&mut self, id: TimerId)
Resume a paused timer from its frozen countdown.
Mirrors lv_timer_resume.
Sourcepub fn delete(&mut self, id: TimerId) -> bool
pub fn delete(&mut self, id: TimerId) -> bool
Remove a timer without firing a final callback.
Returns true if the id was registered, false if not found. Mirrors
lv_timer_delete.
Sourcepub fn set_ready(&mut self, id: TimerId)
pub fn set_ready(&mut self, id: TimerId)
Mark a timer as ready: it fires on the next tick
call regardless of its remaining countdown, then the flag clears and
the period-based countdown resumes. Mirrors lv_timer_ready.