use crate::{ConstInit, EventKey, EventMouse, EventPointer, EventWindow};
#[doc = crate::_tags!(event uid)]
#[doc = crate::_doc_location!("ui/event")]
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub enum EventTag {
#[default]
None,
Key,
Mouse,
Pointer,
Window,
}
#[doc = crate::_tags!(event)]
#[doc = crate::_doc_location!("ui/event")]
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub enum EventKind {
#[default]
None,
Key(EventKey),
Mouse(EventMouse),
Pointer(EventPointer),
Window(EventWindow),
}
impl ConstInit for EventKind {
const INIT: Self = Self::None;
}
impl EventKind {
pub const fn tag(&self) -> EventTag {
match self {
Self::None => EventTag::None,
Self::Key(_) => EventTag::Key,
Self::Mouse(_) => EventTag::Mouse,
Self::Pointer(_) => EventTag::Pointer,
Self::Window(_) => EventTag::Window,
}
}
}
#[rustfmt::skip]
impl EventKind {
#[must_use] #[inline(always)]
pub const fn is_none(&self) -> bool { matches![self, EventKind::None] }
#[must_use] #[inline(always)]
pub const fn is_some(&self) -> bool { !matches![self, EventKind::None] }
#[must_use] #[inline(always)]
pub const fn is_window(&self) -> bool { matches![self, EventKind::Window(_)] }
#[must_use] #[inline(always)]
pub const fn is_key(&self) -> bool { matches![self, EventKind::Key(_)] }
#[must_use] #[inline(always)]
pub const fn is_mouse(&self) -> bool { matches![self, EventKind::Mouse(_)] }
#[must_use] #[inline(always)]
pub const fn is_pointer(&self) -> bool { matches![self, EventKind::Pointer(_)] }
#[must_use] #[inline(always)]
pub const fn some_window(&self) -> Option<&EventWindow> {
if let EventKind::Window(e) = &self { Some(e) } else { None }
}
#[must_use] #[inline(always)]
pub const fn some_key(&self) -> Option<&EventKey> {
if let EventKind::Key(e) = &self { Some(e) } else { None }
}
#[must_use] #[inline(always)]
pub const fn some_mouse(&self) -> Option<&EventMouse> {
if let EventKind::Mouse(e) = &self { Some(e) } else { None }
}
#[must_use] #[inline(always)]
pub const fn some_pointer(&self) -> Option<&EventPointer> {
if let EventKind::Pointer(e) = &self { Some(e) } else { None }
}
}