ailloli_ui_runtime/app/
scheduler.rs

1//! Minimal frame-work flags retained for compatibility.
2
3/// Pending layout and paint work for a frame.
4///
5/// Layout implies paint when marked through [`Self::mark_layout`], but the
6/// public fields permit callers to represent any combination. [`Default`]
7/// equals [`Self::clear`].
8///
9/// # Examples
10///
11/// ```
12/// use ailloli_ui_runtime::app::Scheduler;
13/// let scheduler = Scheduler::default();
14/// assert!(!scheduler.needs_layout && !scheduler.needs_paint);
15/// ```
16#[derive(Debug, Default, Clone)]
17pub struct Scheduler {
18    /// Whether retained layout should be recomputed.
19    pub needs_layout: bool,
20    /// Whether a new scene should be painted.
21    pub needs_paint: bool,
22}
23
24/// Provides the operations defined for Scheduler.
25impl Scheduler {
26    /// Marks both layout and its required follow-up paint as pending.
27    ///
28    /// Calling this repeatedly is idempotent.
29    ///
30    /// # Examples
31    ///
32    /// ```
33    /// use ailloli_ui_runtime::app::Scheduler;
34    /// let mut scheduler = Scheduler::default();
35    /// scheduler.mark_layout();
36    /// assert!(scheduler.needs_layout && scheduler.needs_paint);
37    /// ```
38    pub fn mark_layout(&mut self) {
39        self.needs_layout = true;
40        self.needs_paint = true;
41    }
42
43    /// Marks paint pending without changing the layout flag.
44    ///
45    /// # Examples
46    ///
47    /// ```
48    /// use ailloli_ui_runtime::app::Scheduler;
49    /// let mut scheduler = Scheduler::default();
50    /// scheduler.mark_paint();
51    /// assert!(!scheduler.needs_layout && scheduler.needs_paint);
52    /// ```
53    pub fn mark_paint(&mut self) {
54        self.needs_paint = true;
55    }
56
57    /// Clears both pending-work flags.
58    ///
59    /// # Examples
60    ///
61    /// ```
62    /// use ailloli_ui_runtime::app::Scheduler;
63    /// let mut scheduler = Scheduler { needs_layout: true, needs_paint: true };
64    /// scheduler.clear();
65    /// assert_eq!((scheduler.needs_layout, scheduler.needs_paint), (false, false));
66    /// ```
67    pub fn clear(&mut self) {
68        self.needs_layout = false;
69        self.needs_paint = false;
70    }
71}