pixel_widgets/
event.rs

1/// A key
2#[allow(missing_docs)]
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum Key {
5    LeftMouseButton,
6    MiddleMouseButton,
7    RightMouseButton,
8
9    Key1,
10    Key2,
11    Key3,
12    Key4,
13    Key5,
14    Key6,
15    Key7,
16    Key8,
17    Key9,
18    Key0,
19
20    F1,
21    F2,
22    F3,
23    F4,
24    F5,
25    F6,
26    F7,
27    F8,
28    F9,
29    F10,
30    F11,
31    F12,
32
33    A,
34    B,
35    C,
36    D,
37    E,
38    F,
39    G,
40    H,
41    I,
42    J,
43    K,
44    L,
45    M,
46    N,
47    O,
48    P,
49    Q,
50    R,
51    S,
52    T,
53    U,
54    V,
55    W,
56    X,
57    Y,
58    Z,
59
60    Tab,
61    Shift,
62    Ctrl,
63    Alt,
64    Space,
65    Enter,
66    Backspace,
67    Escape,
68    Home,
69    End,
70    Minus,
71    Plus,
72    BracketOpen,
73    BracketClose,
74    Comma,
75    Period,
76    Semicolon,
77    Quote,
78    Tilde,
79    Backslash,
80    Slash,
81
82    Left,
83    Right,
84    Up,
85    Down,
86}
87
88/// A set of modifiers
89#[derive(Clone, Copy, Debug)]
90pub struct Modifiers {
91    /// `true` if the control key is pressed, `false otherwise.
92    pub ctrl: bool,
93    /// `true` if the alt key is pressed, `false otherwise.
94    pub alt: bool,
95    /// `true` if the shift key is pressed, `false otherwise.
96    pub shift: bool,
97    /// `true` if the windows/super/command key is pressed, `false otherwise.
98    pub logo: bool,
99    /// `true` if the primary key combination key is presesed, `false` otherwise.
100    /// This is command on macos, control on other OS'es.
101    pub command: bool,
102}
103
104#[allow(missing_docs)]
105impl Modifiers {
106    pub fn none() -> Modifiers {
107        Modifiers {
108            ctrl: false,
109            alt: false,
110            shift: false,
111            logo: false,
112            command: false,
113        }
114    }
115
116    pub fn ctrl() -> Modifiers {
117        Modifiers {
118            ctrl: true,
119            alt: false,
120            shift: false,
121            logo: false,
122            #[cfg(target_os = "macos")]
123            command: false,
124            #[cfg(not(target_os = "macos"))]
125            command: true,
126        }
127    }
128
129    pub fn alt() -> Modifiers {
130        Modifiers {
131            ctrl: false,
132            alt: true,
133            shift: false,
134            logo: false,
135            command: false,
136        }
137    }
138
139    pub fn shift() -> Modifiers {
140        Modifiers {
141            ctrl: false,
142            alt: false,
143            shift: true,
144            logo: false,
145            command: false,
146        }
147    }
148
149    pub fn logo() -> Modifiers {
150        Modifiers {
151            ctrl: false,
152            alt: false,
153            shift: false,
154            logo: true,
155            #[cfg(target_os = "macos")]
156            command: true,
157            #[cfg(not(target_os = "macos"))]
158            command: false,
159        }
160    }
161}
162
163/// A user input event.
164#[derive(Clone, Copy, Debug)]
165pub enum Event {
166    /// A button on some input device was pressed.
167    Press(Key),
168    /// A button on some input device was released.
169    Release(Key),
170    /// Modifiers were changed.
171    Modifiers(Modifiers),
172    /// The window was resized to the given dimensions.
173    Resize(f32, f32),
174    /// Some motion input was received (e.g. moving mouse or joystick axis).
175    Motion(f32, f32),
176    /// The mouse cursor was moved to a location.
177    Cursor(f32, f32),
178    /// The mouse wheel or touchpad scroll gesture sent us some scroll event.
179    Scroll(f32, f32),
180    /// Text input was received, usually via the keyboard.
181    Text(char),
182    /// The window was focused or lost focus.
183    Focus(bool),
184    /// The application exited it's main event loop
185    Exit,
186}