#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum InteractionMode {
#[default]
Enabled,
Disabled,
ReadOnly,
}
impl InteractionMode {
pub fn is_enabled(self) -> bool {
matches!(self, Self::Enabled)
}
pub fn is_disabled(self) -> bool {
matches!(self, Self::Disabled)
}
pub fn is_read_only(self) -> bool {
matches!(self, Self::ReadOnly)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InteractionOutcome<T> {
Ignored,
Handled,
Changed(T),
Submitted(T),
Cancelled,
}
impl<T> InteractionOutcome<T> {
pub fn is_handled(&self) -> bool {
!matches!(self, Self::Ignored)
}
pub fn is_changed(&self) -> bool {
matches!(self, Self::Changed(_))
}
pub fn is_submitted(&self) -> bool {
matches!(self, Self::Submitted(_))
}
pub fn is_cancelled(&self) -> bool {
matches!(self, Self::Cancelled)
}
pub fn payload(&self) -> Option<&T> {
match self {
Self::Changed(value) | Self::Submitted(value) => Some(value),
Self::Ignored | Self::Handled | Self::Cancelled => None,
}
}
}