1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
2pub struct Modifiers {
3 pub control: bool,
4 pub alt: bool,
5 pub shift: bool,
6 pub meta: bool,
7}
8
9#[derive(Clone, Debug, PartialEq, Eq)]
10pub enum Key {
11 Character(String),
12 Enter,
13 Escape,
14 Tab,
15 Backspace,
16 Delete,
17 ArrowLeft,
18 ArrowRight,
19 ArrowUp,
20 ArrowDown,
21 Home,
22 End,
23 PageUp,
24 PageDown,
25}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq)]
28pub enum PointerButton {
29 Primary,
30 Secondary,
31 Middle,
32}
33
34#[derive(Clone, Debug, PartialEq)]
35pub enum InputEvent {
36 KeyDown {
37 key: Key,
38 modifiers: Modifiers,
39 },
40 KeyUp {
41 key: Key,
42 modifiers: Modifiers,
43 },
44 PointerDown {
45 x: f32,
46 y: f32,
47 button: PointerButton,
48 modifiers: Modifiers,
49 },
50 PointerMove {
51 x: f32,
52 y: f32,
53 modifiers: Modifiers,
54 },
55 PointerUp {
56 x: f32,
57 y: f32,
58 button: PointerButton,
59 modifiers: Modifiers,
60 },
61 Wheel {
62 x: f32,
63 y: f32,
64 dx: f32,
65 dy: f32,
66 },
67 Resize {
68 width: f32,
69 height: f32,
70 },
71 Tick,
76 FocusGained,
77 FocusLost,
78}
79
80impl InputEvent {
81 pub fn is_save_shortcut(&self) -> bool {
82 matches!(
83 self,
84 Self::KeyDown {
85 key: Key::Character(value),
86 modifiers: Modifiers { control: true, shift: false, .. }
87 } if value.eq_ignore_ascii_case("s")
88 )
89 }
90}