1use crate::Vec2;
2use std::cell::Cell;
3use std::rc::Rc;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
6pub struct PointerId(pub u64);
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum PointerKind {
10 Mouse,
11 Touch,
12 Pen,
13}
14
15#[derive(Clone, Copy, Debug)]
16pub enum PointerButton {
17 Primary, Secondary, Tertiary, }
21
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub enum PointerEventPass {
24 Initial,
27 Main,
31 Final,
34}
35
36#[derive(Clone, Copy, Debug)]
37pub enum PointerEventKind {
38 Down(PointerButton),
39 Up(PointerButton),
40 Move,
41 Cancel,
42 Enter,
43 Leave,
44}
45
46#[derive(Clone, Debug)]
47pub struct PointerEvent {
48 pub id: PointerId,
49 pub kind: PointerKind,
50 pub event: PointerEventKind,
51 pub position: Vec2,
52 pub pressure: f32,
53 pub modifiers: Modifiers,
54 pub consumed: Rc<Cell<bool>>,
57}
58
59impl PointerEvent {
60 pub fn new(
61 id: PointerId,
62 kind: PointerKind,
63 event: PointerEventKind,
64 position: Vec2,
65 pressure: f32,
66 modifiers: Modifiers,
67 ) -> Self {
68 Self {
69 id,
70 kind,
71 event,
72 position,
73 pressure,
74 modifiers,
75 consumed: Rc::new(Cell::new(false)),
76 }
77 }
78
79 pub fn consume(&self) {
83 self.consumed.set(true);
84 }
85
86 pub fn is_consumed(&self) -> bool {
88 self.consumed.get()
89 }
90}
91
92#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
93pub struct Modifiers {
94 pub shift: bool,
95 pub ctrl: bool,
96 pub alt: bool,
97 pub meta: bool, pub command: bool, }
100
101#[derive(Clone, Debug, PartialEq, Eq, Hash)]
102pub enum Key {
103 Character(char),
104 Enter,
105 Tab,
106 Backspace,
107 Delete,
108 Escape,
109 ArrowLeft,
110 ArrowRight,
111 ArrowUp,
112 ArrowDown,
113 Home,
114 End,
115 PageUp,
116 PageDown,
117 Space,
118 F(u8), Unknown,
120}
121
122#[derive(Clone, Copy, Debug, PartialEq, Eq)]
123pub enum KeyEventType {
124 Down,
126 Up,
128 Unknown,
130}
131
132#[derive(Clone, Debug)]
133pub struct KeyEvent {
134 pub key: Key,
135 pub modifiers: Modifiers,
136 pub is_repeat: bool,
137 pub event_type: KeyEventType,
139 pub utf16_code_point: u16,
142}
143
144#[derive(Clone, Debug)]
145pub struct TextInputEvent {
146 pub text: String,
147}
148
149#[derive(Clone, Debug)]
150pub enum ImeEvent {
151 Start,
153 Update {
155 text: String,
156 cursor: Option<(usize, usize)>, },
158 Commit(String),
160 Cancel,
162}
163
164#[derive(Clone, Debug)]
165pub enum InputEvent {
166 Pointer(PointerEvent),
167 Key(KeyEvent),
168 Text(TextInputEvent),
169 Ime(ImeEvent),
170}