use crate::{ConstInit, Event, EventKind};
use crate::{Extent, Position};
#[cfg(feature = "alloc")]
use crate::String;
#[doc = crate::_tags!(event interaction)]
#[doc = crate::_doc_location!("ui/event")]
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum EventWindow {
Resized(Option<Extent<u32, 2>>),
Moved(Option<Position<i32, 2>>),
FocusGained,
FocusLost,
CloseRequested,
Shown,
Hidden,
RedrawRequested,
Minimized,
Maximized,
Restored,
FullscreenEntered,
FullscreenExited,
Entered,
Left,
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
Paste(String),
Continue,
EndOfInput,
}
impl ConstInit for EventWindow {
const INIT: Self = Self::FocusLost;
}
impl From<EventWindow> for EventKind {
fn from(window_event: EventWindow) -> EventKind {
EventKind::Window(window_event)
}
}
impl From<EventWindow> for Event {
fn from(window_event: EventWindow) -> Event {
EventKind::from(window_event).into()
}
}
impl EventWindow {
pub const fn is_geometry(&self) -> bool {
matches!(self, Self::Resized(_) | Self::Moved(_))
}
pub const fn is_resize(&self) -> bool {
matches!(self, Self::Resized(_))
}
pub const fn resize_coord(&self) -> Option<Extent<u32, 2>> {
if let EventWindow::Resized(e) = self { *e } else { None }
}
pub const fn is_move(&self) -> bool {
matches!(self, Self::Moved(_))
}
pub const fn move_coord(&self) -> Option<Position<i32, 2>> {
if let EventWindow::Moved(e) = self { *e } else { None }
}
pub const fn is_focus(&self) -> bool {
matches!(self, Self::FocusGained | Self::FocusLost)
}
pub const fn is_close(&self) -> bool {
matches!(self, Self::CloseRequested)
}
pub const fn is_redraw(&self) -> bool {
matches!(self, Self::RedrawRequested)
}
pub const fn is_visibility(&self) -> bool {
matches!(
self,
Self::Shown
| Self::Hidden
| Self::Minimized
| Self::Restored
| Self::Maximized
| Self::FullscreenEntered
| Self::FullscreenExited
)
}
pub const fn is_pointer_crossing(&self) -> bool {
matches!(self, Self::Entered | Self::Left)
}
#[cfg(feature = "alloc")]
pub const fn is_text_input(&self) -> bool {
matches!(self, Self::Paste(_))
}
pub const fn is_stream_signal(&self) -> bool {
matches!(self, Self::Continue | Self::EndOfInput)
}
}