ailloli_ui_runtime/element/
dirty_flags.rs

1//! Dirty-state flags used to schedule retained layout, paint, and input work.
2
3/// Independent retained-element work flags.
4///
5/// Layout invalidation conventionally also requires paint, while input work is
6/// independent. The public fields can express any combination; constructors
7/// provide the combinations used by the runtime.
8///
9/// # Examples
10///
11/// ```
12/// use ailloli_ui_runtime::element::DirtyFlags;
13/// let dirty = DirtyFlags::layout();
14/// assert!(dirty.layout && dirty.paint && !dirty.input);
15/// ```
16#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
17pub struct DirtyFlags {
18    /// `true` when cached layout must be recomputed.
19    pub layout: bool,
20    /// `true` when draw commands must be regenerated.
21    pub paint: bool,
22    /// `true` when input-derived data must be refreshed.
23    pub input: bool,
24}
25
26/// Provides the operations defined for DirtyFlags.
27impl DirtyFlags {
28    /// Returns all work flags cleared.
29    ///
30    /// # Examples
31    ///
32    /// ```
33    /// use ailloli_ui_runtime::element::DirtyFlags;
34    /// assert_eq!(DirtyFlags::clean(), DirtyFlags::default());
35    /// ```
36    pub const fn clean() -> Self {
37        Self {
38            layout: false,
39            paint: false,
40            input: false,
41        }
42    }
43
44    /// Returns layout and paint dirty, with input clean.
45    ///
46    /// # Examples
47    ///
48    /// ```
49    /// use ailloli_ui_runtime::element::DirtyFlags;
50    /// let flags = DirtyFlags::layout();
51    /// assert!((flags.layout, flags.paint, flags.input) == (true, true, false));
52    /// ```
53    pub const fn layout() -> Self {
54        Self {
55            layout: true,
56            paint: true,
57            input: false,
58        }
59    }
60
61    /// Returns only paint dirty.
62    ///
63    /// # Examples
64    ///
65    /// ```
66    /// use ailloli_ui_runtime::element::DirtyFlags;
67    /// let flags = DirtyFlags::paint();
68    /// assert!(!flags.layout && flags.paint && !flags.input);
69    /// ```
70    pub const fn paint() -> Self {
71        Self {
72            layout: false,
73            paint: true,
74            input: false,
75        }
76    }
77
78    /// Returns only input dirty.
79    ///
80    /// # Examples
81    ///
82    /// ```
83    /// use ailloli_ui_runtime::element::DirtyFlags;
84    /// let flags = DirtyFlags::input();
85    /// assert!(!flags.layout && !flags.paint && flags.input);
86    /// ```
87    pub const fn input() -> Self {
88        Self {
89            layout: false,
90            paint: false,
91            input: true,
92        }
93    }
94}