geng_window/
events.rs

1use super::*;
2
3#[derive(
4    Debug,
5    Copy,
6    Clone,
7    PartialEq,
8    Eq,
9    Hash,
10    Serialize,
11    Deserialize,
12    strum::EnumString,
13    strum::Display,
14)]
15pub enum MouseButton {
16    Left,
17    Middle,
18    Right,
19}
20
21#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
22pub struct Touch {
23    pub id: u64,
24    // TODO force
25    pub position: vec2<f64>,
26}
27
28#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
29pub enum Event {
30    MousePress { button: MouseButton },
31    MouseRelease { button: MouseButton },
32    CursorMove { position: vec2<f64> },
33    RawMouseMove { delta: vec2<f64> },
34    Wheel { delta: f64 },
35    TouchStart(Touch),
36    TouchMove(Touch),
37    TouchEnd(Touch),
38    KeyPress { key: Key },
39    KeyRelease { key: Key },
40    EditText(String),
41    Draw,
42    CloseRequested,
43    Focused(bool),
44}
45
46impl Event {
47    pub fn translate(&self, delta: vec2<f64>) -> Self {
48        let mut result = self.clone();
49        use Event::*;
50        match result {
51            CursorMove {
52                ref mut position, ..
53            } => *position += delta,
54            TouchStart(ref mut touch) | TouchMove(ref mut touch) | TouchEnd(ref mut touch) => {
55                touch.position += delta;
56            }
57            _ => {}
58        }
59        result
60    }
61}
62
63#[derive(
64    Debug,
65    Copy,
66    Clone,
67    PartialEq,
68    Eq,
69    Hash,
70    Serialize,
71    Deserialize,
72    strum::EnumString,
73    strum::Display,
74)]
75#[non_exhaustive]
76pub enum Key {
77    /// <kbd>`</kbd> on a US keyboard. This is also called a backtick or grave.
78    /// This is the <kbd>半角</kbd>/<kbd>全角</kbd>/<kbd>漢字</kbd>
79    /// (hankaku/zenkaku/kanji) key on Japanese keyboards
80    Backquote,
81    /// Used for both the US <kbd>\\</kbd> (on the 101-key layout) and also for the key
82    /// located between the <kbd>"</kbd> and <kbd>Enter</kbd> keys on row C of the 102-,
83    /// 104- and 106-key layouts.
84    /// Labeled <kbd>#</kbd> on a UK (102) keyboard.
85    Backslash,
86    /// <kbd>[</kbd> on a US keyboard.
87    BracketLeft,
88    /// <kbd>]</kbd> on a US keyboard.
89    BracketRight,
90    /// <kbd>,</kbd> on a US keyboard.
91    Comma,
92    /// <kbd>0</kbd> on a US keyboard.
93    Digit0,
94    /// <kbd>1</kbd> on a US keyboard.
95    Digit1,
96    /// <kbd>2</kbd> on a US keyboard.
97    Digit2,
98    /// <kbd>3</kbd> on a US keyboard.
99    Digit3,
100    /// <kbd>4</kbd> on a US keyboard.
101    Digit4,
102    /// <kbd>5</kbd> on a US keyboard.
103    Digit5,
104    /// <kbd>6</kbd> on a US keyboard.
105    Digit6,
106    /// <kbd>7</kbd> on a US keyboard.
107    Digit7,
108    /// <kbd>8</kbd> on a US keyboard.
109    Digit8,
110    /// <kbd>9</kbd> on a US keyboard.
111    Digit9,
112    /// <kbd>=</kbd> on a US keyboard.
113    Equal,
114    /// Located between the left <kbd>Shift</kbd> and <kbd>Z</kbd> keys.
115    /// Labeled <kbd>\\</kbd> on a UK keyboard.
116    IntlBackslash,
117    /// Located between the <kbd>/</kbd> and right <kbd>Shift</kbd> keys.
118    /// Labeled <kbd>\\</kbd> (ro) on a Japanese keyboard.
119    IntlRo,
120    /// Located between the <kbd>=</kbd> and <kbd>Backspace</kbd> keys.
121    /// Labeled <kbd>¥</kbd> (yen) on a Japanese keyboard. <kbd>\\</kbd> on a
122    /// Russian keyboard.
123    IntlYen,
124    /// <kbd>a</kbd> on a US keyboard.
125    /// Labeled <kbd>q</kbd> on an AZERTY (e.g., French) keyboard.
126    A,
127    /// <kbd>b</kbd> on a US keyboard.
128    B,
129    /// <kbd>c</kbd> on a US keyboard.
130    C,
131    /// <kbd>d</kbd> on a US keyboard.
132    D,
133    /// <kbd>e</kbd> on a US keyboard.
134    E,
135    /// <kbd>f</kbd> on a US keyboard.
136    F,
137    /// <kbd>g</kbd> on a US keyboard.
138    G,
139    /// <kbd>h</kbd> on a US keyboard.
140    H,
141    /// <kbd>i</kbd> on a US keyboard.
142    I,
143    /// <kbd>j</kbd> on a US keyboard.
144    J,
145    /// <kbd>k</kbd> on a US keyboard.
146    K,
147    /// <kbd>l</kbd> on a US keyboard.
148    L,
149    /// <kbd>m</kbd> on a US keyboard.
150    M,
151    /// <kbd>n</kbd> on a US keyboard.
152    N,
153    /// <kbd>o</kbd> on a US keyboard.
154    O,
155    /// <kbd>p</kbd> on a US keyboard.
156    P,
157    /// <kbd>q</kbd> on a US keyboard.
158    /// Labeled <kbd>a</kbd> on an AZERTY (e.g., French) keyboard.
159    Q,
160    /// <kbd>r</kbd> on a US keyboard.
161    R,
162    /// <kbd>s</kbd> on a US keyboard.
163    S,
164    /// <kbd>t</kbd> on a US keyboard.
165    T,
166    /// <kbd>u</kbd> on a US keyboard.
167    U,
168    /// <kbd>v</kbd> on a US keyboard.
169    V,
170    /// <kbd>w</kbd> on a US keyboard.
171    /// Labeled <kbd>z</kbd> on an AZERTY (e.g., French) keyboard.
172    W,
173    /// <kbd>x</kbd> on a US keyboard.
174    X,
175    /// <kbd>y</kbd> on a US keyboard.
176    /// Labeled <kbd>z</kbd> on a QWERTZ (e.g., German) keyboard.
177    Y,
178    /// <kbd>z</kbd> on a US keyboard.
179    /// Labeled <kbd>w</kbd> on an AZERTY (e.g., French) keyboard, and <kbd>y</kbd> on a
180    /// QWERTZ (e.g., German) keyboard.
181    Z,
182    /// <kbd>-</kbd> on a US keyboard.
183    Minus,
184    /// <kbd>.</kbd> on a US keyboard.
185    Period,
186    /// <kbd>'</kbd> on a US keyboard.
187    Quote,
188    /// <kbd>;</kbd> on a US keyboard.
189    Semicolon,
190    /// <kbd>/</kbd> on a US keyboard.
191    Slash,
192    /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
193    AltLeft,
194    /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>.
195    /// This is labeled <kbd>AltGr</kbd> on many keyboard layouts.
196    AltRight,
197    /// <kbd>Backspace</kbd> or <kbd>⌫</kbd>.
198    /// Labeled <kbd>Delete</kbd> on Apple keyboards.
199    Backspace,
200    /// <kbd>CapsLock</kbd> or <kbd>⇪</kbd>
201    CapsLock,
202    /// The application context menu key, which is typically found between the right
203    /// <kbd>Super</kbd> key and the right <kbd>Control</kbd> key.
204    ContextMenu,
205    /// <kbd>Control</kbd> or <kbd>⌃</kbd>
206    ControlLeft,
207    /// <kbd>Control</kbd> or <kbd>⌃</kbd>
208    ControlRight,
209    /// <kbd>Enter</kbd> or <kbd>↵</kbd>. Labeled <kbd>Return</kbd> on Apple keyboards.
210    Enter,
211    /// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
212    SuperLeft,
213    /// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
214    SuperRight,
215    /// <kbd>Shift</kbd> or <kbd>⇧</kbd>
216    ShiftLeft,
217    /// <kbd>Shift</kbd> or <kbd>⇧</kbd>
218    ShiftRight,
219    /// <kbd> </kbd> (space)
220    Space,
221    /// <kbd>Tab</kbd> or <kbd>⇥</kbd>
222    Tab,
223    /// <kbd>⌦</kbd>. The forward delete key.
224    /// Note that on Apple keyboards, the key labelled <kbd>Delete</kbd> on the main part of
225    /// the keyboard is encoded as [`Backspace`].
226    ///
227    /// [`Backspace`]: Self::Backspace
228    Delete,
229    /// <kbd>Page Down</kbd>, <kbd>End</kbd>, or <kbd>↘</kbd>
230    End,
231    /// <kbd>Help</kbd>. Not present on standard PC keyboards.
232    Help,
233    /// <kbd>Home</kbd> or <kbd>↖</kbd>
234    Home,
235    /// <kbd>Insert</kbd> or <kbd>Ins</kbd>. Not present on Apple keyboards.
236    Insert,
237    /// <kbd>Page Down</kbd>, <kbd>PgDn</kbd>, or <kbd>⇟</kbd>
238    PageDown,
239    /// <kbd>Page Up</kbd>, <kbd>PgUp</kbd>, or <kbd>⇞</kbd>
240    PageUp,
241    /// <kbd>↓</kbd>
242    ArrowDown,
243    /// <kbd>←</kbd>
244    ArrowLeft,
245    /// <kbd>→</kbd>
246    ArrowRight,
247    /// <kbd>↑</kbd>
248    ArrowUp,
249    /// On the Mac, this is used for the numpad <kbd>Clear</kbd> key.
250    NumLock,
251    /// <kbd>0 Ins</kbd> on a keyboard. <kbd>0</kbd> on a phone or remote control
252    Numpad0,
253    /// <kbd>1 End</kbd> on a keyboard. <kbd>1</kbd> or <kbd>1 QZ</kbd> on a phone or remote control
254    Numpad1,
255    /// <kbd>2 ↓</kbd> on a keyboard. <kbd>2 ABC</kbd> on a phone or remote control
256    Numpad2,
257    /// <kbd>3 PgDn</kbd> on a keyboard. <kbd>3 DEF</kbd> on a phone or remote control
258    Numpad3,
259    /// <kbd>4 ←</kbd> on a keyboard. <kbd>4 GHI</kbd> on a phone or remote control
260    Numpad4,
261    /// <kbd>5</kbd> on a keyboard. <kbd>5 JKL</kbd> on a phone or remote control
262    Numpad5,
263    /// <kbd>6 →</kbd> on a keyboard. <kbd>6 MNO</kbd> on a phone or remote control
264    Numpad6,
265    /// <kbd>7 Home</kbd> on a keyboard. <kbd>7 PQRS</kbd> or <kbd>7 PRS</kbd> on a phone
266    /// or remote control
267    Numpad7,
268    /// <kbd>8 ↑</kbd> on a keyboard. <kbd>8 TUV</kbd> on a phone or remote control
269    Numpad8,
270    /// <kbd>9 PgUp</kbd> on a keyboard. <kbd>9 WXYZ</kbd> or <kbd>9 WXY</kbd> on a phone
271    /// or remote control
272    Numpad9,
273    /// <kbd>+</kbd>
274    NumpadAdd,
275    /// Found on the Microsoft Natural Keyboard.
276    NumpadBackspace,
277    /// <kbd>C</kbd> or <kbd>A</kbd> (All Clear). Also for use with numpads that have a
278    /// <kbd>Clear</kbd> key that is separate from the <kbd>NumLock</kbd> key. On the Mac, the
279    /// numpad <kbd>Clear</kbd> key is encoded as [`NumLock`].
280    ///
281    /// [`NumLock`]: Self::NumLock
282    NumpadClear,
283    /// <kbd>C</kbd> (Clear Entry)
284    NumpadClearEntry,
285    /// <kbd>,</kbd> (thousands separator). For locales where the thousands separator
286    /// is a "." (e.g., Brazil), this key may generate a <kbd>.</kbd>.
287    NumpadComma,
288    /// <kbd>. Del</kbd>. For locales where the decimal separator is "," (e.g.,
289    /// Brazil), this key may generate a <kbd>,</kbd>.
290    NumpadDecimal,
291    /// <kbd>/</kbd>
292    NumpadDivide,
293    NumpadEnter,
294    /// <kbd>=</kbd>
295    NumpadEqual,
296    /// <kbd>#</kbd> on a phone or remote control device. This key is typically found
297    /// below the <kbd>9</kbd> key and to the right of the <kbd>0</kbd> key.
298    NumpadHash,
299    /// <kbd>M</kbd> Add current entry to the value stored in memory.
300    NumpadMemoryAdd,
301    /// <kbd>M</kbd> Clear the value stored in memory.
302    NumpadMemoryClear,
303    /// <kbd>M</kbd> Replace the current entry with the value stored in memory.
304    NumpadMemoryRecall,
305    /// <kbd>M</kbd> Replace the value stored in memory with the current entry.
306    NumpadMemoryStore,
307    /// <kbd>M</kbd> Subtract current entry from the value stored in memory.
308    NumpadMemorySubtract,
309    /// <kbd>*</kbd> on a keyboard. For use with numpads that provide mathematical
310    /// operations (<kbd>+</kbd>, <kbd>-</kbd> <kbd>*</kbd> and <kbd>/</kbd>).
311    ///
312    /// Use `NumpadStar` for the <kbd>*</kbd> key on phones and remote controls.
313    NumpadMultiply,
314    /// <kbd>(</kbd> Found on the Microsoft Natural Keyboard.
315    NumpadParenLeft,
316    /// <kbd>)</kbd> Found on the Microsoft Natural Keyboard.
317    NumpadParenRight,
318    /// <kbd>*</kbd> on a phone or remote control device.
319    ///
320    /// This key is typically found below the <kbd>7</kbd> key and to the left of
321    /// the <kbd>0</kbd> key.
322    ///
323    /// Use <kbd>"NumpadMultiply"</kbd> for the <kbd>*</kbd> key on
324    /// numeric keypads.
325    NumpadStar,
326    /// <kbd>-</kbd>
327    NumpadSubtract,
328    /// <kbd>Esc</kbd> or <kbd>⎋</kbd>
329    Escape,
330    /// Some laptops place this key to the left of the <kbd>↑</kbd> key.
331    ///
332    /// This also the "back" button (triangle) on Android.
333    Back,
334    /// General-purpose function key.
335    /// Usually found at the top of the keyboard.
336    F1,
337    /// General-purpose function key.
338    /// Usually found at the top of the keyboard.
339    F2,
340    /// General-purpose function key.
341    /// Usually found at the top of the keyboard.
342    F3,
343    /// General-purpose function key.
344    /// Usually found at the top of the keyboard.
345    F4,
346    /// General-purpose function key.
347    /// Usually found at the top of the keyboard.
348    F5,
349    /// General-purpose function key.
350    /// Usually found at the top of the keyboard.
351    F6,
352    /// General-purpose function key.
353    /// Usually found at the top of the keyboard.
354    F7,
355    /// General-purpose function key.
356    /// Usually found at the top of the keyboard.
357    F8,
358    /// General-purpose function key.
359    /// Usually found at the top of the keyboard.
360    F9,
361    /// General-purpose function key.
362    /// Usually found at the top of the keyboard.
363    F10,
364    /// General-purpose function key.
365    /// Usually found at the top of the keyboard.
366    F11,
367    /// General-purpose function key.
368    /// Usually found at the top of the keyboard.
369    F12,
370}