1use sdl3::{
2 keyboard::{Keycode, Mod, Scancode},
3 mouse::{MouseButton, MouseState, MouseWheelDirection},
4};
5
6pub struct KeyboardEvent {
7 pub timestamp: u64,
8 pub window_id: u32,
9 pub keycode: Option<Keycode>,
10 pub scancode: Option<Scancode>,
11 pub keymod: Mod,
12 pub repeat: bool,
13 pub which: u32,
14 pub raw: u16,
15}
16
17pub struct MouseMotionEvent {
18 pub timestamp: u64,
19 pub window_id: u32,
20 pub which: u32,
21 pub mousestate: MouseState,
22 pub x: f32,
23 pub y: f32,
24 pub xrel: f32,
25 pub yrel: f32,
26}
27
28pub struct MouseClickEvent {
29 pub timestamp: u64,
30 pub window_id: u32,
31 pub which: u32,
32 pub mouse_btn: MouseButton,
33 pub clicks: u8,
34 pub x: f32,
35 pub y: f32,
36}
37
38pub struct MouseWheelEvent {
39 pub timestamp: u64,
40 pub window_id: u32,
41 pub which: u32,
42 pub x: f32,
43 pub y: f32,
44 pub direction: MouseWheelDirection,
45 pub mouse_x: f32,
46 pub mouse_y: f32,
47}
48
49#[async_trait::async_trait]
50pub trait WindowEventHandler: Send + Sync {
51 type Host;
52
53 fn update(&self, host: &mut Self::Host) -> anyhow::Result<()>;
54 fn draw(&self, host: &mut Self::Host) -> anyhow::Result<()>;
55
56 fn key_down_event(&self, _host: &mut Self::Host, _event: KeyboardEvent) -> anyhow::Result<()> {
57 Ok(())
58 }
59 fn key_up_event(&self, _host: &mut Self::Host, _event: KeyboardEvent) -> anyhow::Result<()> {
60 Ok(())
61 }
62 fn mouse_motion_event(
63 &self,
64 _host: &mut Self::Host,
65 _event: MouseMotionEvent,
66 ) -> anyhow::Result<()> {
67 Ok(())
68 }
69 fn mouse_button_down_event(
70 &self,
71 _host: &mut Self::Host,
72 _event: MouseClickEvent,
73 ) -> anyhow::Result<()> {
74 Ok(())
75 }
76 fn mouse_button_up_event(
77 &self,
78 _host: &mut Self::Host,
79 _event: MouseClickEvent,
80 ) -> anyhow::Result<()> {
81 Ok(())
82 }
83 fn mouse_wheel_event(
84 &self,
85 _host: &mut Self::Host,
86 _event: MouseWheelEvent,
87 ) -> anyhow::Result<()> {
88 Ok(())
89 }
90}