1/// A trait for elements that can be selected.
2///
3/// Generally used to enable "toggle" or "active" behavior and styles on an element through the [`Selection`] status.
4pub trait Selectable {
5 /// Sets whether the element is selected.
6 fn selected(self, selected: bool) -> Self;
7}
8
9/// Represents the selection status of an element.
10#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
11pub enum Selection {
12 /// The element is not selected.
13 #[default]
14 Unselected,
15 /// The selection state of the element is indeterminate.
16 Indeterminate,
17 /// The element is selected.
18 Selected,
19}
20
21impl Selection {
22 /// Returns the inverse of the current selection status.
23 ///
24 /// Indeterminate states become selected if inverted.
25 pub fn inverse(&self) -> Self {
26 match self {
27 Self::Unselected | Self::Indeterminate => Self::Selected,
28 Self::Selected => Self::Unselected,
29 }
30 }
31}