1use super::AxisId;
2use super::DeviceId;
3use super::ElementState;
4use super::KeyboardInput;
5use super::ModifiersState;
6use super::MouseButton;
7use super::MouseButtonState;
8use super::MouseScrollDelta;
9use super::Theme;
10use super::Touch;
11use super::TouchPhase;
12use crate::WindowId;
13
14use std::path::PathBuf;
15
16#[derive(Debug, Clone)]
18pub enum WindowEvent {
19 RedrawRequested(WindowRedrawRequestedEvent),
21
22 Resized(WindowResizedEvent),
24
25 Moved(WindowMovedEvent),
27
28 CloseRequested(WindowCloseRequestedEvent),
30
31 Destroyed(WindowDestroyedEvent),
33
34 DroppedFile(WindowDroppedFileEvent),
36
37 HoveredFile(WindowHoveredFileEvent),
39
40 HoveredFileCancelled(WindowHoveredFileCancelledEvent),
42
43 FocusGained(WindowFocusGainedEvent),
45
46 FocusLost(WindowFocusLostEvent),
48
49 KeyboardInput(WindowKeyboardInputEvent),
51
52 TextInput(WindowTextInputEvent),
54
55 MouseEnter(WindowMouseEnterEvent),
57
58 MouseLeave(WindowMouseLeaveEvent),
60
61 MouseMove(WindowMouseMoveEvent),
63
64 MouseButton(WindowMouseButtonEvent),
66
67 MouseWheel(WindowMouseWheelEvent),
69
70 AxisMotion(WindowAxisMotionEvent),
72
73 TouchpadPressure(WindowTouchpadPressureEvent),
75
76 TouchpadMagnify(WindowTouchpadMagnifyEvent),
82
83 TouchpadRotate(WindowTouchpadRotateEvent),
89
90 Touch(WindowTouchEvent),
92
93 ScaleFactorChanged(WindowScaleFactorChangedEvent),
95
96 ThemeChanged(WindowThemeChangedEvent),
98}
99
100impl WindowEvent {
101 pub fn window_id(&self) -> WindowId {
103 match self {
104 Self::RedrawRequested(x) => x.window_id,
105 Self::Resized(x) => x.window_id,
106 Self::Moved(x) => x.window_id,
107 Self::CloseRequested(x) => x.window_id,
108 Self::Destroyed(x) => x.window_id,
109 Self::DroppedFile(x) => x.window_id,
110 Self::HoveredFile(x) => x.window_id,
111 Self::HoveredFileCancelled(x) => x.window_id,
112 Self::FocusGained(x) => x.window_id,
113 Self::FocusLost(x) => x.window_id,
114 Self::KeyboardInput(x) => x.window_id,
115 Self::TextInput(x) => x.window_id,
116 Self::MouseEnter(x) => x.window_id,
117 Self::MouseLeave(x) => x.window_id,
118 Self::MouseMove(x) => x.window_id,
119 Self::MouseButton(x) => x.window_id,
120 Self::MouseWheel(x) => x.window_id,
121 Self::AxisMotion(x) => x.window_id,
122 Self::TouchpadPressure(x) => x.window_id,
123 Self::TouchpadMagnify(x) => x.window_id,
124 Self::TouchpadRotate(x) => x.window_id,
125 Self::Touch(x) => x.window_id,
126 Self::ScaleFactorChanged(x) => x.window_id,
127 Self::ThemeChanged(x) => x.window_id,
128 }
129 }
130}
131
132#[derive(Debug, Clone)]
134pub struct WindowRedrawRequestedEvent {
135 pub window_id: WindowId,
137}
138
139#[derive(Debug, Clone)]
141pub struct WindowResizedEvent {
142 pub window_id: WindowId,
144
145 pub size: glam::UVec2,
147}
148
149#[derive(Debug, Clone)]
151pub struct WindowMovedEvent {
152 pub window_id: WindowId,
154
155 pub position: glam::IVec2,
157}
158
159#[derive(Debug, Clone)]
161pub struct WindowCloseRequestedEvent {
162 pub window_id: WindowId,
164}
165
166#[derive(Debug, Clone)]
168pub struct WindowDestroyedEvent {
169 pub window_id: WindowId,
171}
172
173#[derive(Debug, Clone)]
175pub struct WindowDroppedFileEvent {
176 pub window_id: WindowId,
178
179 pub file: PathBuf,
181}
182
183#[derive(Debug, Clone)]
185pub struct WindowHoveredFileEvent {
186 pub window_id: WindowId,
188
189 pub file: PathBuf,
191}
192
193#[derive(Debug, Clone)]
195pub struct WindowHoveredFileCancelledEvent {
196 pub window_id: WindowId,
198}
199
200#[derive(Debug, Clone)]
202pub struct WindowFocusGainedEvent {
203 pub window_id: WindowId,
205}
206
207#[derive(Debug, Clone)]
209pub struct WindowFocusLostEvent {
210 pub window_id: WindowId,
212}
213
214#[derive(Debug, Clone)]
216pub struct WindowKeyboardInputEvent {
217 pub window_id: WindowId,
219
220 pub device_id: DeviceId,
222
223 pub input: KeyboardInput,
225
226 pub is_synthetic: bool,
231}
232
233#[derive(Debug, Clone)]
235pub struct WindowTextInputEvent {
236 pub window_id: WindowId,
238
239 pub character: char,
241}
242
243#[derive(Debug, Clone)]
245pub struct WindowMouseEnterEvent {
246 pub window_id: WindowId,
248
249 pub device_id: DeviceId,
251
252 pub buttons: MouseButtonState,
254}
255
256#[derive(Debug, Clone)]
258pub struct WindowMouseLeaveEvent {
259 pub window_id: WindowId,
261
262 pub device_id: DeviceId,
264
265 pub buttons: MouseButtonState,
267}
268
269#[derive(Debug, Clone)]
271pub struct WindowMouseMoveEvent {
272 pub window_id: WindowId,
274
275 pub device_id: DeviceId,
277
278 pub position: glam::Vec2,
280
281 pub prev_position: glam::Vec2,
283
284 pub buttons: MouseButtonState,
286
287 pub modifiers: ModifiersState,
289}
290
291#[derive(Debug, Clone)]
293pub struct WindowMouseButtonEvent {
294 pub window_id: WindowId,
296
297 pub device_id: DeviceId,
299
300 pub button: MouseButton,
302
303 pub state: ElementState,
305
306 pub position: glam::Vec2,
308
309 pub prev_position: glam::Vec2,
311
312 pub buttons: MouseButtonState,
314
315 pub modifiers: ModifiersState,
317}
318
319#[derive(Debug, Clone)]
321pub struct WindowMouseWheelEvent {
322 pub window_id: WindowId,
324
325 pub device_id: DeviceId,
327
328 pub delta: MouseScrollDelta,
330
331 pub phase: TouchPhase,
333
334 pub position: Option<glam::Vec2>,
336
337 pub buttons: MouseButtonState,
339
340 pub modifiers: ModifiersState,
342}
343
344#[derive(Debug, Clone)]
346pub struct WindowAxisMotionEvent {
347 pub window_id: WindowId,
349
350 pub device_id: DeviceId,
352
353 pub axis: AxisId,
355
356 pub value: f64,
358}
359
360#[derive(Debug, Clone)]
362pub struct WindowTouchpadPressureEvent {
363 pub window_id: WindowId,
365
366 pub device_id: DeviceId,
368
369 pub pressure: f32,
371
372 pub stage: i64,
374}
375
376#[derive(Debug, Clone)]
378pub struct WindowTouchpadMagnifyEvent {
379 pub window_id: WindowId,
381
382 pub device_id: DeviceId,
384
385 pub scale: f64,
390
391 pub phase: TouchPhase,
393}
394
395#[derive(Debug, Clone)]
397pub struct WindowTouchpadRotateEvent {
398 pub window_id: WindowId,
400
401 pub device_id: DeviceId,
403
404 pub angle_radians: f64,
408
409 pub phase: TouchPhase,
411}
412
413#[derive(Debug, Clone)]
415pub struct WindowTouchEvent {
416 pub window_id: WindowId,
418
419 pub touch: Touch,
421}
422
423#[derive(Debug, Clone)]
425pub struct WindowScaleFactorChangedEvent {
426 pub window_id: WindowId,
428
429 pub scale_factor: f64,
431}
432
433#[derive(Debug, Clone)]
435pub struct WindowThemeChangedEvent {
436 pub window_id: WindowId,
438
439 pub theme: Theme,
441}
442
443impl_from_variant!(WindowEvent::RedrawRequested(WindowRedrawRequestedEvent));
444impl_from_variant!(WindowEvent::Resized(WindowResizedEvent));
445impl_from_variant!(WindowEvent::Moved(WindowMovedEvent));
446impl_from_variant!(WindowEvent::CloseRequested(WindowCloseRequestedEvent));
447impl_from_variant!(WindowEvent::Destroyed(WindowDestroyedEvent));
448impl_from_variant!(WindowEvent::DroppedFile(WindowDroppedFileEvent));
449impl_from_variant!(WindowEvent::HoveredFile(WindowHoveredFileEvent));
450impl_from_variant!(WindowEvent::HoveredFileCancelled(WindowHoveredFileCancelledEvent));
451impl_from_variant!(WindowEvent::FocusGained(WindowFocusGainedEvent));
452impl_from_variant!(WindowEvent::FocusLost(WindowFocusLostEvent));
453impl_from_variant!(WindowEvent::KeyboardInput(WindowKeyboardInputEvent));
454impl_from_variant!(WindowEvent::TextInput(WindowTextInputEvent));
455impl_from_variant!(WindowEvent::MouseEnter(WindowMouseEnterEvent));
456impl_from_variant!(WindowEvent::MouseLeave(WindowMouseLeaveEvent));
457impl_from_variant!(WindowEvent::MouseMove(WindowMouseMoveEvent));
458impl_from_variant!(WindowEvent::MouseButton(WindowMouseButtonEvent));
459impl_from_variant!(WindowEvent::MouseWheel(WindowMouseWheelEvent));
460impl_from_variant!(WindowEvent::AxisMotion(WindowAxisMotionEvent));
461impl_from_variant!(WindowEvent::TouchpadPressure(WindowTouchpadPressureEvent));
462impl_from_variant!(WindowEvent::TouchpadMagnify(WindowTouchpadMagnifyEvent));
463impl_from_variant!(WindowEvent::TouchpadRotate(WindowTouchpadRotateEvent));
464impl_from_variant!(WindowEvent::Touch(WindowTouchEvent));
465impl_from_variant!(WindowEvent::ScaleFactorChanged(WindowScaleFactorChangedEvent));
466impl_from_variant!(WindowEvent::ThemeChanged(WindowThemeChangedEvent));