ailloli_ui_core/event/mod.rs
1//! Platform-neutral UI events.
2//!
3//! `ailloli_ui_winit` maps `winit` events into these types before the runtime
4//! routes them to focused widgets.
5//!
6//! # Matching extensible payloads
7//!
8//! Provider-produced payloads that may gain platform-neutral data are marked
9//! `#[non_exhaustive]`. Consumer matches must include a fallback arm. Construct
10//! events through their lowercase constructors (for example,
11//! [`PointerEvent::button`](crate::event::PointerEvent::button),
12//! [`FileEvent::dropped`](crate::event::FileEvent::dropped), or
13//! [`ImeEvent::commit`](crate::event::ImeEvent::commit))
14//! instead of depending on exhaustive framework internals. `MouseButton`
15//! remains a compatibility alias; new code should use
16//! [`PointerButton`](crate::event::PointerButton).
17//!
18//! The top-level [`Event`](crate::event::Event) boundary is extensible too.
19//! Consumer matches must therefore retain a fallback arm when matching either
20//! the envelope or one of its provider-produced payloads.
21
22/// File hover/drop batches and compatibility variants.
23///
24/// # Examples
25///
26/// ```
27/// use ailloli_ui_core::event::file::FileEvent;
28/// assert!(FileEvent::left().is_left());
29/// ```
30pub mod file;
31/// Runtime focus gain/loss notifications.
32///
33/// # Examples
34///
35/// ```
36/// use ailloli_ui_core::event::focus::FocusEvent;
37/// assert!(FocusEvent::new(true).focused);
38/// ```
39pub mod focus;
40/// Input Method Editor composition and commit payloads.
41///
42/// # Examples
43///
44/// ```
45/// use ailloli_ui_core::event::ime::ImeEvent;
46/// assert_eq!(ImeEvent::commit("文").committed_text(), Some("文"));
47/// ```
48pub mod ime;
49/// Keyboard keys, modifiers, and transition payloads.
50///
51/// # Examples
52///
53/// ```
54/// use ailloli_ui_core::event::keyboard::KeyState;
55/// assert_ne!(KeyState::Pressed, KeyState::Released);
56/// ```
57pub mod keyboard;
58/// Pointer sources, samples, buttons, motion, and wheel payloads.
59///
60/// # Examples
61///
62/// ```
63/// use ailloli_ui_core::event::pointer::PointerId;
64/// assert_eq!(PointerId::MOUSE.get(), 0);
65/// ```
66pub mod pointer;
67/// Window surface and lifecycle notifications.
68///
69/// # Examples
70///
71/// ```
72/// use ailloli_ui_core::event::window::WindowEvent;
73/// assert!(matches!(WindowEvent::CloseRequested, WindowEvent::CloseRequested));
74/// ```
75pub mod window;
76
77pub use file::FileEvent;
78pub use focus::FocusEvent;
79pub use ime::{ImeEvent, ImePreedit, ImePreeditError};
80pub use keyboard::{Key, KeyEvent, KeyState, Modifiers, NamedKey};
81pub use pointer::{
82 ActivationKind, MouseButton, PointerButton, PointerEvent, PointerId, PointerSample,
83 PointerSampleError, PointerSource, WheelDelta,
84};
85pub use window::WindowEvent;
86
87/// Top-level event envelope delivered to the runtime.
88///
89/// Possible values wrap pointer, keyboard, IME, focus, file, and window
90/// payloads.
91///
92/// # Examples
93///
94/// ```
95/// use ailloli_ui_core::event::{Event, FocusEvent};
96/// let event = Event::Focus(FocusEvent::new(true));
97/// assert!(matches!(event, Event::Focus(_)));
98/// ```
99#[non_exhaustive]
100#[derive(Debug, Clone, PartialEq)]
101pub enum Event {
102 /// Pointer move, button, or wheel.
103 Pointer(PointerEvent),
104 /// Key press/release with optional text.
105 Keyboard(KeyEvent),
106 /// IME composition lifecycle.
107 Ime(ImeEvent),
108 /// Runtime focus/blur notification.
109 Focus(FocusEvent),
110 /// Platform-neutral file hover/drop notification.
111 File(FileEvent),
112 /// Window resize, focus, close, redraw.
113 Window(WindowEvent),
114}