1pub use device::*;
4pub use window::*;
5
6pub use winit::event::AxisId;
7pub use winit::event::ButtonId;
8pub use winit::event::DeviceId;
9pub use winit::event::Force;
10pub use winit::event::ModifiersState;
11pub use winit::event::MouseScrollDelta;
12pub use winit::event::ScanCode;
13pub use winit::event::StartCause;
14pub use winit::event::Touch;
15pub use winit::event::TouchPhase;
16pub use winit::event::VirtualKeyCode;
17
18macro_rules! impl_from_variant {
19 ($for:ident::$variant:ident($from:ty)) => {
20 impl From<$from> for $for {
21 fn from(other: $from) -> Self {
22 Self::$variant(other)
23 }
24 }
25 };
26}
27
28mod device;
29mod window;
30
31#[derive(Debug, Default, Clone)]
36pub struct EventHandlerControlFlow {
37 pub remove_handler: bool,
39
40 pub stop_propagation: bool,
42}
43
44#[derive(Debug, Clone)]
48pub enum Event {
49 NewEvents,
53
54 WindowEvent(WindowEvent),
56
57 DeviceEvent(DeviceEvent),
59
60 Suspended,
62
63 Resumed,
65
66 MainEventsCleared,
68
69 RedrawEventsCleared,
71
72 AllWindowsClosed,
76}
77
78impl_from_variant!(Event::WindowEvent(WindowEvent));
79impl_from_variant!(Event::DeviceEvent(DeviceEvent));
80
81#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
83pub struct KeyboardInput {
84 pub scan_code: ScanCode,
89
90 pub key_code: Option<VirtualKeyCode>,
94
95 pub state: ElementState,
97
98 pub modifiers: ModifiersState,
100}
101
102#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
104pub enum Theme {
105 Light,
107
108 Dark,
110}
111
112impl Theme {
113 pub fn is_light(self) -> bool {
115 self == Self::Light
116 }
117
118 pub fn is_dark(self) -> bool {
120 self == Self::Dark
121 }
122}
123
124#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
126pub enum ElementState {
127 Pressed,
129
130 Released,
132}
133
134impl ElementState {
135 pub fn is_pressed(self) -> bool {
137 self == Self::Pressed
138 }
139
140 pub fn is_released(self) -> bool {
142 self == Self::Released
143 }
144}
145
146#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
147pub enum MouseButton {
149 Left,
151
152 Right,
154
155 Middle,
157
158 Other(u16),
160}
161
162impl MouseButton {
163 pub fn is_left(self) -> bool {
165 self == Self::Left
166 }
167
168 pub fn is_right(self) -> bool {
170 self == Self::Right
171 }
172
173 pub fn is_middle(self) -> bool {
175 self == Self::Middle
176 }
177
178 pub fn is_other(self, other: u16) -> bool {
180 self == Self::Other(other)
181 }
182}
183
184#[derive(Debug, Clone, Default)]
186pub struct MouseButtonState {
187 buttons: std::collections::BTreeSet<MouseButton>,
189}
190
191impl MouseButtonState {
192 pub fn is_pressed(&self, button: MouseButton) -> bool {
194 self.buttons.get(&button).is_some()
195 }
196
197 pub fn iter_pressed(&self) -> impl Iterator<Item = MouseButton> + '_ {
199 self.buttons.iter().copied()
200 }
201
202 pub fn set_pressed(&mut self, button: MouseButton, pressed: bool) {
204 if pressed {
205 self.buttons.insert(button);
206 } else {
207 self.buttons.remove(&button);
208 }
209 }
210}