1use crate::geom::Size;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Key {
6 Char(char),
7 Enter,
8 Esc,
9 Backspace,
10 Tab,
11 Up,
12 Down,
13 Left,
14 Right,
15 Delete,
16 Home,
17 End,
18 PageUp,
19 PageDown,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
24pub struct Modifiers {
25 pub ctrl: bool,
26 pub alt: bool,
27 pub shift: bool,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct KeyEvent {
33 pub key: Key,
34 pub modifiers: Modifiers,
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum MouseKind {
40 Down,
41 Up,
42 ScrollUp,
43 ScrollDown,
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub struct MouseEvent {
49 pub x: u16,
50 pub y: u16,
51 pub kind: MouseKind,
52}
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum EventPhase {
57 Capture,
59 Target,
61 Bubble,
63}
64
65#[derive(Debug, Clone, PartialEq, Eq)]
67pub enum Event {
68 Key(KeyEvent),
69 Mouse(MouseEvent),
70 Resize(Size),
71 Focus,
73 Blur,
75 Tick,
76 TaskComplete(String),
78}
79
80#[derive(Debug, Clone, PartialEq, Eq)]
82pub enum Command {
83 Quit,
84 FocusNext,
85 FocusPrev,
86 Custom(String),
87}
88
89impl Event {
90 pub fn is_key(&self, key: Key) -> bool {
92 matches!(self, Event::Key(KeyEvent { key: k, .. }) if *k == key)
93 }
94}