use crate::{_impl_init, impl_trait, is, set};
#[doc = crate::_tags!(event interaction member)]
#[doc = crate::_doc_meta!{
location("ui/event"),
test_size_of(EventButton = 2|16; niche Option),
}]
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum EventButton {
#[default]
Left,
Right,
Middle,
X1,
X2,
X3,
X4,
X5,
Other(u8),
}
_impl_init! { Self::Left => EventButton }
impl EventButton {
pub const fn new(number: u8) -> Option<Self> {
match number {
1 => Some(Self::Left),
2 => Some(Self::Middle),
3 => Some(Self::Right),
_ => Some(Self::Other(number)),
}
}
#[inline(always)]
pub const fn from_one_bit_mask(mask: EventButtons) -> Option<EventButton> {
match mask.bits() {
1 => Some(EventButton::Left),
2 => Some(EventButton::Right),
4 => Some(EventButton::Middle),
8 => Some(EventButton::X1),
16 => Some(EventButton::X2),
32 => Some(EventButton::X3),
64 => Some(EventButton::X4),
128 => Some(EventButton::X5),
_ => None,
}
}
#[inline(always)]
pub const fn to_mask(self) -> EventButtons {
match self {
Self::Left => EventButtons::new().with(EventButtons::LEFT),
Self::Right => EventButtons::new().with(EventButtons::RIGHT),
Self::Middle => EventButtons::new().with(EventButtons::MIDDLE),
Self::X1 => EventButtons::new().with(EventButtons::X1),
Self::X2 => EventButtons::new().with(EventButtons::X2),
Self::X3 => EventButtons::new().with(EventButtons::X3),
Self::X4 => EventButtons::new().with(EventButtons::X4),
Self::X5 => EventButtons::new().with(EventButtons::X5),
Self::Other(_) => EventButtons::new(),
}
}
}
#[doc = crate::_tags!(event interaction)]
#[doc = crate::_doc_meta!{location("ui/event")}]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum EventButtonState {
#[default]
Pressed,
Released,
Moved,
}
_impl_init! { Self::Pressed => EventButtonState }
set! {
#[doc = crate::_tags!(event interaction set)]
#[doc = crate::_doc_meta!{
location("ui/event"),
test_size_of(EventButtons = 1|8), // option = 2|16
}]
pub struct EventButtons(u8) {
LEFT = 0;
RIGHT = 1;
MIDDLE = 2;
X1 = 3;
X2 = 4;
X3 = 5;
X4 = 6;
X5 = 7;
}
traits(!Debug);
}
impl_trait! { fmt::Debug for EventButtons |self, f| {
let l = is![self.has_left(), "L", "-"];
let r = is![self.has_right(), "R", "-"];
let m = is![self.has_middle(), "M", "-"];
let x1 = is![self.has_x1(), "1", "-"];
let x2 = is![self.has_x2(), "2", "-"];
let x3 = is![self.has_x3(), "3", "-"];
let x4 = is![self.has_x4(), "4", "-"];
let x5 = is![self.has_x5(), "5", "-"];
write![f, "{l}{r}{m}{x1}{x2}{x3}{x4}{x5}"]
} }