selectable.rs

 1use gpui::{AnyView, WindowContext};
 2
 3/// A trait for elements that can be selected.
 4pub trait Selectable {
 5    /// Sets whether the element is selected.
 6    fn selected(self, selected: bool) -> Self;
 7
 8    /// Sets the tooltip that should be shown when the element is selected.
 9    fn selected_tooltip(
10        self,
11        tooltip: Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>,
12    ) -> Self;
13}
14
15#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
16pub enum Selection {
17    #[default]
18    Unselected,
19    Indeterminate,
20    Selected,
21}
22
23impl Selection {
24    pub fn inverse(&self) -> Self {
25        match self {
26            Self::Unselected | Self::Indeterminate => Self::Selected,
27            Self::Selected => Self::Unselected,
28        }
29    }
30}