rich_sdl2_rust/event/
window.rs1use crate::{
4 bind,
5 geo::{Point, Size},
6 EnumInt,
7};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11#[non_exhaustive]
12pub enum WindowEventDetails {
13 Shown,
15 Hidden,
17 Exposed,
19 Moved(Point),
21 Resized(Size),
23 SizeChanged(Size),
25 Minimized,
27 Maximized,
29 Restored,
31 Enter,
33 Leave,
35 FocusGained,
37 FocusLost,
39 Close,
41 TakeFocus,
43}
44
45#[derive(Debug, Clone)]
47pub struct WindowEvent {
48 pub timestamp: u32,
50 pub window_id: u32,
52 pub details: WindowEventDetails,
54}
55
56impl From<bind::SDL_WindowEvent> for WindowEvent {
57 fn from(
58 bind::SDL_WindowEvent {
59 timestamp,
60 windowID: window_id,
61 event,
62 data1,
63 data2,
64 ..
65 }: bind::SDL_WindowEvent,
66 ) -> Self {
67 Self {
68 timestamp,
69 window_id,
70 details: match event as EnumInt {
71 bind::SDL_WINDOWEVENT_SHOWN => WindowEventDetails::Shown,
72 bind::SDL_WINDOWEVENT_HIDDEN => WindowEventDetails::Hidden,
73 bind::SDL_WINDOWEVENT_EXPOSED => WindowEventDetails::Exposed,
74 bind::SDL_WINDOWEVENT_MOVED => {
75 WindowEventDetails::Moved(Point { x: data1, y: data2 })
76 }
77 bind::SDL_WINDOWEVENT_RESIZED => WindowEventDetails::Resized(Size {
78 width: data1 as u32,
79 height: data2 as u32,
80 }),
81 bind::SDL_WINDOWEVENT_SIZE_CHANGED => WindowEventDetails::SizeChanged(Size {
82 width: data1 as u32,
83 height: data2 as u32,
84 }),
85 bind::SDL_WINDOWEVENT_MINIMIZED => WindowEventDetails::Minimized,
86 bind::SDL_WINDOWEVENT_MAXIMIZED => WindowEventDetails::Maximized,
87 bind::SDL_WINDOWEVENT_RESTORED => WindowEventDetails::Restored,
88 bind::SDL_WINDOWEVENT_ENTER => WindowEventDetails::Enter,
89 bind::SDL_WINDOWEVENT_LEAVE => WindowEventDetails::Leave,
90 bind::SDL_WINDOWEVENT_FOCUS_GAINED => WindowEventDetails::FocusGained,
91 bind::SDL_WINDOWEVENT_FOCUS_LOST => WindowEventDetails::FocusLost,
92 bind::SDL_WINDOWEVENT_CLOSE => WindowEventDetails::Close,
93 bind::SDL_WINDOWEVENT_TAKE_FOCUS => WindowEventDetails::TakeFocus,
94 other => todo!("{other} is not implemented"),
95 },
96 }
97 }
98}