ZIm/crates/ui2/src/selectable.rs
Marshall Bowers 9d53287341
Implement Selectable for buttons (#3451)
This PR implements the `Selectable` trait for `ButtonLike`, `Button`,
and `IconButton`.

Release Notes:

- N/A
2023-11-29 18:46:41 -05:00

22 lines
524 B
Rust

/// A trait for elements that can be selected.
pub trait Selectable {
/// Sets whether the element is selected.
fn selected(self, selected: bool) -> Self;
}
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
pub enum Selection {
#[default]
Unselected,
Indeterminate,
Selected,
}
impl Selection {
pub fn inverse(&self) -> Self {
match self {
Self::Unselected | Self::Indeterminate => Self::Selected,
Self::Selected => Self::Unselected,
}
}
}