1use std::fmt::{Display, Formatter};
18use std::marker::PhantomData;
19
20use crate::dimen::{IVec2, UVec2, Vec2};
21use crate::error::{BacktraceError, ErrorMessage};
22use crate::{GLRenderer, Graphics2D};
23
24#[cfg(all(not(target_arch = "wasm32"), not(any(doc, doctest))))]
25type WindowHelperInnerType<UserEventType> =
26 crate::window_internal_glutin::WindowHelperGlutin<UserEventType>;
27
28#[cfg(all(not(target_arch = "wasm32"), not(any(doc, doctest))))]
29type UserEventSenderInnerType<UserEventType> =
30 crate::window_internal_glutin::UserEventSenderGlutin<UserEventType>;
31
32#[cfg(all(target_arch = "wasm32", not(any(doc, doctest))))]
33type WindowHelperInnerType<UserEventType> =
34 crate::window_internal_web::WindowHelperWeb<UserEventType>;
35
36#[cfg(all(target_arch = "wasm32", not(any(doc, doctest))))]
37type UserEventSenderInnerType<UserEventType> =
38 crate::window_internal_web::UserEventSenderWeb<UserEventType>;
39
40#[cfg(any(doc, doctest))]
41type WindowHelperInnerType<UserEventType> = PhantomData<UserEventType>;
42
43#[cfg(any(doc, doctest))]
44type UserEventSenderInnerType<UserEventType> = PhantomData<UserEventType>;
45
46#[derive(Clone, Debug, Hash, Eq, PartialEq, Copy)]
48pub enum EventLoopSendError
49{
50 EventLoopNoLongerExists
52}
53
54pub struct UserEventSender<UserEventType: 'static>
56{
57 inner: UserEventSenderInnerType<UserEventType>
58}
59
60impl<UserEventType> Clone for UserEventSender<UserEventType>
61{
62 fn clone(&self) -> Self
63 {
64 UserEventSender {
65 inner: self.inner.clone()
66 }
67 }
68}
69
70impl<UserEventType> UserEventSender<UserEventType>
71{
72 pub(crate) fn new(inner: UserEventSenderInnerType<UserEventType>) -> Self
73 {
74 Self { inner }
75 }
76
77 #[inline]
84 pub fn send_event(&self, event: UserEventType) -> Result<(), EventLoopSendError>
85 {
86 self.inner.send_event(event)
87 }
88}
89
90#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
92#[non_exhaustive]
93pub enum WindowCreationError
94{
95 PrimaryMonitorNotFound,
97 SuitableContextNotFound,
101 MakeContextCurrentFailed,
103 RendererCreationFailed,
105 EventLoopCreationFailed
107}
108
109impl Display for WindowCreationError
110{
111 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result
112 {
113 f.write_str(match self {
114 WindowCreationError::PrimaryMonitorNotFound => "Primary monitor not found",
115 WindowCreationError::SuitableContextNotFound => {
116 "Could not find a suitable graphics context"
117 }
118 WindowCreationError::MakeContextCurrentFailed => {
119 "Failed to make the graphics context current"
120 }
121 WindowCreationError::RendererCreationFailed => {
122 "Failed to create the renderer"
123 }
124 WindowCreationError::EventLoopCreationFailed => {
125 "Failed to instantiate the main window event loop"
126 }
127 })
128 }
129}
130
131pub trait WindowHandler<UserEventType = ()>
135{
136 #[allow(unused_variables)]
138 #[inline]
139 fn on_start(
140 &mut self,
141 helper: &mut WindowHelper<UserEventType>,
142 info: WindowStartupInfo
143 )
144 {
145 }
146
147 #[allow(unused_variables)]
152 #[inline]
153 fn on_user_event(
154 &mut self,
155 helper: &mut WindowHelper<UserEventType>,
156 user_event: UserEventType
157 )
158 {
159 }
160
161 #[allow(unused_variables)]
163 #[inline]
164 fn on_resize(&mut self, helper: &mut WindowHelper<UserEventType>, size_pixels: UVec2)
165 {
166 }
167
168 #[allow(unused_variables)]
174 #[inline]
175 fn on_mouse_grab_status_changed(
176 &mut self,
177 helper: &mut WindowHelper<UserEventType>,
178 mouse_grabbed: bool
179 )
180 {
181 }
182
183 #[allow(unused_variables)]
186 #[inline]
187 fn on_fullscreen_status_changed(
188 &mut self,
189 helper: &mut WindowHelper<UserEventType>,
190 fullscreen: bool
191 )
192 {
193 }
194
195 #[allow(unused_variables)]
197 #[inline]
198 fn on_scale_factor_changed(
199 &mut self,
200 helper: &mut WindowHelper<UserEventType>,
201 scale_factor: f64
202 )
203 {
204 }
205
206 #[allow(unused_variables)]
211 #[inline]
212 fn on_draw(
213 &mut self,
214 helper: &mut WindowHelper<UserEventType>,
215 graphics: &mut Graphics2D
216 )
217 {
218 }
219
220 #[allow(unused_variables)]
229 #[inline]
230 fn on_mouse_move(&mut self, helper: &mut WindowHelper<UserEventType>, position: Vec2)
231 {
232 }
233
234 #[allow(unused_variables)]
236 #[inline]
237 fn on_mouse_button_down(
238 &mut self,
239 helper: &mut WindowHelper<UserEventType>,
240 button: MouseButton
241 )
242 {
243 }
244
245 #[allow(unused_variables)]
247 #[inline]
248 fn on_mouse_button_up(
249 &mut self,
250 helper: &mut WindowHelper<UserEventType>,
251 button: MouseButton
252 )
253 {
254 }
255
256 #[allow(unused_variables)]
258 #[inline]
259 fn on_mouse_wheel_scroll(
260 &mut self,
261 helper: &mut WindowHelper<UserEventType>,
262 distance: MouseScrollDistance
263 )
264 {
265 }
266
267 #[allow(unused_variables)]
272 #[inline]
273 fn on_key_down(
274 &mut self,
275 helper: &mut WindowHelper<UserEventType>,
276 virtual_key_code: Option<VirtualKeyCode>,
277 scancode: KeyScancode
278 )
279 {
280 }
281
282 #[allow(unused_variables)]
284 #[inline]
285 fn on_key_up(
286 &mut self,
287 helper: &mut WindowHelper<UserEventType>,
288 virtual_key_code: Option<VirtualKeyCode>,
289 scancode: KeyScancode
290 )
291 {
292 }
293
294 #[allow(unused_variables)]
299 #[inline]
300 fn on_keyboard_char(
301 &mut self,
302 helper: &mut WindowHelper<UserEventType>,
303 unicode_codepoint: char
304 )
305 {
306 }
307
308 #[allow(unused_variables)]
310 #[inline]
311 fn on_keyboard_modifiers_changed(
312 &mut self,
313 helper: &mut WindowHelper<UserEventType>,
314 state: ModifiersState
315 )
316 {
317 }
318}
319
320impl<UserEventType, H> WindowHandler<UserEventType> for Box<H>
323where
324 H: WindowHandler<UserEventType> + ?Sized
325{
326 #[inline]
327 fn on_start(
328 &mut self,
329 helper: &mut WindowHelper<UserEventType>,
330 info: WindowStartupInfo
331 )
332 {
333 (**self).on_start(helper, info)
334 }
335
336 #[inline]
337 fn on_user_event(
338 &mut self,
339 helper: &mut WindowHelper<UserEventType>,
340 user_event: UserEventType
341 )
342 {
343 (**self).on_user_event(helper, user_event)
344 }
345
346 #[inline]
347 fn on_resize(&mut self, helper: &mut WindowHelper<UserEventType>, size_pixels: UVec2)
348 {
349 (**self).on_resize(helper, size_pixels)
350 }
351
352 #[inline]
353 fn on_mouse_grab_status_changed(
354 &mut self,
355 helper: &mut WindowHelper<UserEventType>,
356 mouse_grabbed: bool
357 )
358 {
359 (**self).on_mouse_grab_status_changed(helper, mouse_grabbed)
360 }
361
362 #[inline]
363 fn on_fullscreen_status_changed(
364 &mut self,
365 helper: &mut WindowHelper<UserEventType>,
366 fullscreen: bool
367 )
368 {
369 (**self).on_fullscreen_status_changed(helper, fullscreen)
370 }
371
372 #[inline]
373 fn on_scale_factor_changed(
374 &mut self,
375 helper: &mut WindowHelper<UserEventType>,
376 scale_factor: f64
377 )
378 {
379 (**self).on_scale_factor_changed(helper, scale_factor)
380 }
381
382 #[inline]
383 fn on_draw(
384 &mut self,
385 helper: &mut WindowHelper<UserEventType>,
386 graphics: &mut Graphics2D
387 )
388 {
389 (**self).on_draw(helper, graphics)
390 }
391
392 #[inline]
393 fn on_mouse_move(&mut self, helper: &mut WindowHelper<UserEventType>, position: Vec2)
394 {
395 (**self).on_mouse_move(helper, position)
396 }
397
398 #[inline]
399 fn on_mouse_button_down(
400 &mut self,
401 helper: &mut WindowHelper<UserEventType>,
402 button: MouseButton
403 )
404 {
405 (**self).on_mouse_button_down(helper, button)
406 }
407
408 #[inline]
409 fn on_mouse_button_up(
410 &mut self,
411 helper: &mut WindowHelper<UserEventType>,
412 button: MouseButton
413 )
414 {
415 (**self).on_mouse_button_up(helper, button)
416 }
417
418 #[inline]
419 fn on_mouse_wheel_scroll(
420 &mut self,
421 helper: &mut WindowHelper<UserEventType>,
422 distance: MouseScrollDistance
423 )
424 {
425 (**self).on_mouse_wheel_scroll(helper, distance)
426 }
427
428 #[inline]
429 fn on_key_down(
430 &mut self,
431 helper: &mut WindowHelper<UserEventType>,
432 virtual_key_code: Option<VirtualKeyCode>,
433 scancode: KeyScancode
434 )
435 {
436 (**self).on_key_down(helper, virtual_key_code, scancode)
437 }
438
439 #[inline]
440 fn on_key_up(
441 &mut self,
442 helper: &mut WindowHelper<UserEventType>,
443 virtual_key_code: Option<VirtualKeyCode>,
444 scancode: KeyScancode
445 )
446 {
447 (**self).on_key_up(helper, virtual_key_code, scancode)
448 }
449
450 #[inline]
451 fn on_keyboard_char(
452 &mut self,
453 helper: &mut WindowHelper<UserEventType>,
454 unicode_codepoint: char
455 )
456 {
457 (**self).on_keyboard_char(helper, unicode_codepoint)
458 }
459
460 #[inline]
461 fn on_keyboard_modifiers_changed(
462 &mut self,
463 helper: &mut WindowHelper<UserEventType>,
464 state: ModifiersState
465 )
466 {
467 (**self).on_keyboard_modifiers_changed(helper, state)
468 }
469}
470
471pub(crate) struct DrawingWindowHandler<UserEventType, H>
472where
473 UserEventType: 'static,
474 H: WindowHandler<UserEventType>
475{
476 window_handler: H,
477 renderer: GLRenderer,
478 phantom: PhantomData<UserEventType>
479}
480
481impl<UserEventType, H> DrawingWindowHandler<UserEventType, H>
482where
483 H: WindowHandler<UserEventType>,
484 UserEventType: 'static
485{
486 pub fn new(window_handler: H, renderer: GLRenderer) -> Self
487 {
488 DrawingWindowHandler {
489 window_handler,
490 renderer,
491 phantom: PhantomData
492 }
493 }
494
495 #[inline]
496 pub fn on_start(
497 &mut self,
498 helper: &mut WindowHelper<UserEventType>,
499 info: WindowStartupInfo
500 )
501 {
502 self.window_handler.on_start(helper, info);
503 }
504
505 #[inline]
506 pub fn on_user_event(
507 &mut self,
508 helper: &mut WindowHelper<UserEventType>,
509 user_event: UserEventType
510 )
511 {
512 self.window_handler.on_user_event(helper, user_event)
513 }
514
515 #[inline]
516 pub fn on_resize(
517 &mut self,
518 helper: &mut WindowHelper<UserEventType>,
519 size_pixels: UVec2
520 )
521 {
522 self.renderer.set_viewport_size_pixels(size_pixels);
523 self.window_handler.on_resize(helper, size_pixels)
524 }
525
526 #[inline]
527 pub fn on_mouse_grab_status_changed(
528 &mut self,
529 helper: &mut WindowHelper<UserEventType>,
530 mouse_grabbed: bool
531 )
532 {
533 self.window_handler
534 .on_mouse_grab_status_changed(helper, mouse_grabbed)
535 }
536
537 #[inline]
538 pub fn on_fullscreen_status_changed(
539 &mut self,
540 helper: &mut WindowHelper<UserEventType>,
541 fullscreen: bool
542 )
543 {
544 self.window_handler
545 .on_fullscreen_status_changed(helper, fullscreen)
546 }
547
548 #[inline]
549 pub fn on_scale_factor_changed(
550 &mut self,
551 helper: &mut WindowHelper<UserEventType>,
552 scale_factor: f64
553 )
554 {
555 self.window_handler
556 .on_scale_factor_changed(helper, scale_factor)
557 }
558
559 #[inline]
560 pub fn on_draw(&mut self, helper: &mut WindowHelper<UserEventType>)
561 {
562 let renderer = &mut self.renderer;
563 let window_handler = &mut self.window_handler;
564
565 renderer.draw_frame(|graphics| window_handler.on_draw(helper, graphics))
566 }
567
568 #[inline]
569 pub fn on_mouse_move(
570 &mut self,
571 helper: &mut WindowHelper<UserEventType>,
572 position: Vec2
573 )
574 {
575 self.window_handler.on_mouse_move(helper, position)
576 }
577
578 #[inline]
579 pub fn on_mouse_button_down(
580 &mut self,
581 helper: &mut WindowHelper<UserEventType>,
582 button: MouseButton
583 )
584 {
585 self.window_handler.on_mouse_button_down(helper, button)
586 }
587
588 #[inline]
589 pub fn on_mouse_button_up(
590 &mut self,
591 helper: &mut WindowHelper<UserEventType>,
592 button: MouseButton
593 )
594 {
595 self.window_handler.on_mouse_button_up(helper, button)
596 }
597
598 #[inline]
599 pub fn on_mouse_wheel_scroll(
600 &mut self,
601 helper: &mut WindowHelper<UserEventType>,
602 distance: MouseScrollDistance
603 )
604 {
605 self.window_handler.on_mouse_wheel_scroll(helper, distance)
606 }
607
608 #[inline]
609 pub fn on_key_down(
610 &mut self,
611 helper: &mut WindowHelper<UserEventType>,
612 virtual_key_code: Option<VirtualKeyCode>,
613 scancode: KeyScancode
614 )
615 {
616 self.window_handler
617 .on_key_down(helper, virtual_key_code, scancode)
618 }
619
620 #[inline]
621 pub fn on_key_up(
622 &mut self,
623 helper: &mut WindowHelper<UserEventType>,
624 virtual_key_code: Option<VirtualKeyCode>,
625 scancode: KeyScancode
626 )
627 {
628 self.window_handler
629 .on_key_up(helper, virtual_key_code, scancode)
630 }
631
632 #[inline]
633 pub fn on_keyboard_char(
634 &mut self,
635 helper: &mut WindowHelper<UserEventType>,
636 unicode_codepoint: char
637 )
638 {
639 self.window_handler
640 .on_keyboard_char(helper, unicode_codepoint)
641 }
642
643 #[inline]
644 pub fn on_keyboard_modifiers_changed(
645 &mut self,
646 helper: &mut WindowHelper<UserEventType>,
647 state: ModifiersState
648 )
649 {
650 self.window_handler
651 .on_keyboard_modifiers_changed(helper, state)
652 }
653}
654
655pub struct WindowHelper<UserEventType = ()>
657where
658 UserEventType: 'static
659{
660 inner: WindowHelperInnerType<UserEventType>
661}
662
663impl<UserEventType> WindowHelper<UserEventType>
664{
665 pub(crate) fn new(inner: WindowHelperInnerType<UserEventType>) -> Self
666 {
667 WindowHelper { inner }
668 }
669
670 #[inline]
671 #[must_use]
672 pub(crate) fn inner(&mut self) -> &mut WindowHelperInnerType<UserEventType>
673 {
674 &mut self.inner
675 }
676
677 pub fn terminate_loop(&mut self)
691 {
692 self.inner.terminate_loop()
693 }
694
695 pub fn set_icon_from_rgba_pixels<S>(
702 &self,
703 data: Vec<u8>,
704 size: S
705 ) -> Result<(), BacktraceError<ErrorMessage>>
706 where
707 S: Into<UVec2>
708 {
709 self.inner.set_icon_from_rgba_pixels(data, size.into())
710 }
711
712 pub fn set_cursor_visible(&self, visible: bool)
714 {
715 self.inner.set_cursor_visible(visible)
716 }
717
718 pub fn set_cursor_grab(
720 &self,
721 grabbed: bool
722 ) -> Result<(), BacktraceError<ErrorMessage>>
723 {
724 self.inner.set_cursor_grab(grabbed)
725 }
726
727 pub fn set_cursor(&self, cursor: MouseCursorType)
729 {
730 self.inner.set_cursor(cursor)
731 }
732
733 pub fn set_resizable(&self, resizable: bool)
737 {
738 self.inner.set_resizable(resizable)
739 }
740
741 pub fn set_visible(&self, visible: bool)
753 {
754 self.inner.set_visible(visible)
755 }
756
757 #[inline]
762 pub fn request_redraw(&self)
763 {
764 self.inner.request_redraw()
765 }
766
767 pub fn set_title<S: AsRef<str>>(&self, title: S)
769 {
770 self.inner.set_title(title.as_ref())
771 }
772
773 pub fn set_fullscreen_mode(&self, mode: WindowFullscreenMode)
780 {
781 self.inner.set_fullscreen_mode(mode)
782 }
783
784 pub fn set_size_pixels<S: Into<UVec2>>(&self, size: S)
789 {
790 self.inner.set_size_pixels(size)
791 }
792
793 pub fn get_size_pixels(&self) -> UVec2
795 {
796 self.inner.get_size_pixels()
797 }
798
799 pub fn set_position_pixels<P: Into<IVec2>>(&self, position: P)
805 {
806 self.inner.set_position_pixels(position)
807 }
808
809 pub fn set_size_scaled_pixels<S: Into<Vec2>>(&self, size: S)
814 {
815 self.inner.set_size_scaled_pixels(size)
816 }
817
818 pub fn set_position_scaled_pixels<P: Into<Vec2>>(&self, position: P)
824 {
825 self.inner.set_position_scaled_pixels(position)
826 }
827
828 #[inline]
830 #[must_use]
831 pub fn get_scale_factor(&self) -> f64
832 {
833 self.inner.get_scale_factor()
834 }
835
836 pub fn create_user_event_sender(&self) -> UserEventSender<UserEventType>
845 {
846 self.inner.create_user_event_sender()
847 }
848
849 #[cfg(all(not(target_arch = "wasm32"), not(any(doc, doctest))))]
856 pub fn create_window(
857 &self,
858 title: &str,
859 options: WindowCreationOptions,
860 handler: Box<dyn WindowHandler<UserEventType>>
861 )
862 {
863 self.inner.create_window(title, options, handler, false);
864 }
865
866 #[cfg(all(not(target_arch = "wasm32"), not(any(doc, doctest))))]
871 pub fn create_modal_window(
872 &self,
873 title: &str,
874 options: WindowCreationOptions,
875 handler: Box<dyn WindowHandler<UserEventType>>
876 )
877 {
878 self.inner.create_window(title, options, handler, true);
879 }
880
881 #[cfg(all(not(target_arch = "wasm32"), not(any(doc, doctest))))]
884 pub fn close_window(&self)
885 {
886 self.inner.close_window();
887 }
888}
889
890#[cfg(any(doc, doctest, not(target_arch = "wasm32")))]
891#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
892#[must_use]
893pub(crate) enum WindowEventLoopAction
894{
895 Continue,
897
898 Exit
904}
905
906#[derive(Debug, PartialEq, Clone)]
908pub struct WindowStartupInfo
909{
910 viewport_size_pixels: UVec2,
911 scale_factor: f64
912}
913
914impl WindowStartupInfo
915{
916 pub(crate) fn new(viewport_size_pixels: UVec2, scale_factor: f64) -> Self
917 {
918 WindowStartupInfo {
919 viewport_size_pixels,
920 scale_factor
921 }
922 }
923
924 pub fn scale_factor(&self) -> f64
927 {
928 self.scale_factor
929 }
930
931 pub fn viewport_size_pixels(&self) -> &UVec2
933 {
934 &self.viewport_size_pixels
935 }
936}
937
938#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
940#[non_exhaustive]
941pub enum MouseButton
942{
943 Left,
945 Middle,
947 Right,
949 Back,
951 Forward,
953 Other(u16)
955}
956
957#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, Default)]
963#[non_exhaustive]
964pub enum MouseCursorType
965{
966 #[default]
968 Default,
969 Pointer,
971 Crosshair,
973 Text,
975 VerticalText,
977 Move,
979 Grab,
981 Grabbing,
983 Wait,
985 Progress,
988 Cell,
990 Alias,
992 Copy,
994 NoDrop,
997 NotAllowed,
999 ColResize,
1001 RowResize,
1003 EwResize,
1005 NsResize,
1007 NeswResize,
1009 NwseResize,
1011 ZoomIn,
1013 ZoomOut
1015}
1016
1017#[derive(Debug, PartialEq, Clone, Copy)]
1019pub enum MouseScrollDistance
1020{
1021 Lines
1024 {
1025 x: f64,
1028 y: f64,
1031 z: f64
1033 },
1034 Pixels
1039 {
1040 x: f64,
1043 y: f64,
1046 z: f64
1048 },
1049 Pages
1053 {
1054 x: f64,
1057 y: f64,
1060 z: f64
1062 }
1063}
1064
1065#[allow(missing_docs)]
1067#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
1068#[non_exhaustive]
1069pub enum VirtualKeyCode
1070{
1071 Key1,
1072 Key2,
1073 Key3,
1074 Key4,
1075 Key5,
1076 Key6,
1077 Key7,
1078 Key8,
1079 Key9,
1080 Key0,
1081
1082 A,
1083 B,
1084 C,
1085 D,
1086 E,
1087 F,
1088 G,
1089 H,
1090 I,
1091 J,
1092 K,
1093 L,
1094 M,
1095 N,
1096 O,
1097 P,
1098 Q,
1099 R,
1100 S,
1101 T,
1102 U,
1103 V,
1104 W,
1105 X,
1106 Y,
1107 Z,
1108
1109 Escape,
1110
1111 F1,
1112 F2,
1113 F3,
1114 F4,
1115 F5,
1116 F6,
1117 F7,
1118 F8,
1119 F9,
1120 F10,
1121 F11,
1122 F12,
1123 F13,
1124 F14,
1125 F15,
1126 F16,
1127 F17,
1128 F18,
1129 F19,
1130 F20,
1131 F21,
1132 F22,
1133 F23,
1134 F24,
1135
1136 PrintScreen,
1137 ScrollLock,
1138 PauseBreak,
1139
1140 Insert,
1141 Home,
1142 Delete,
1143 End,
1144 PageDown,
1145 PageUp,
1146
1147 Left,
1148 Up,
1149 Right,
1150 Down,
1151
1152 Backspace,
1153 Return,
1154 Space,
1155
1156 Compose,
1157
1158 Caret,
1159
1160 Numlock,
1161 Numpad0,
1162 Numpad1,
1163 Numpad2,
1164 Numpad3,
1165 Numpad4,
1166 Numpad5,
1167 Numpad6,
1168 Numpad7,
1169 Numpad8,
1170 Numpad9,
1171 NumpadAdd,
1172 NumpadDivide,
1173 NumpadDecimal,
1174 NumpadComma,
1175 NumpadEnter,
1176 NumpadEquals,
1177 NumpadMultiply,
1178 NumpadSubtract,
1179
1180 AbntC1,
1181 AbntC2,
1182 Apostrophe,
1183 Apps,
1184 Asterisk,
1185 At,
1186 Ax,
1187 Backslash,
1188 Calculator,
1189 Capital,
1190 Colon,
1191 Comma,
1192 Convert,
1193 Equals,
1194 Grave,
1195 Kana,
1196 Kanji,
1197 LAlt,
1198 LBracket,
1199 LControl,
1200 LShift,
1201 LWin,
1202 Mail,
1203 MediaSelect,
1204 MediaStop,
1205 Minus,
1206 Mute,
1207 MyComputer,
1208 NavigateForward,
1209 NavigateBackward,
1210 NextTrack,
1211 NoConvert,
1212 OEM102,
1213 Period,
1214 PlayPause,
1215 Plus,
1216 Power,
1217 PrevTrack,
1218 RAlt,
1219 RBracket,
1220 RControl,
1221 RShift,
1222 RWin,
1223 Semicolon,
1224 Slash,
1225 Sleep,
1226 Stop,
1227 Sysrq,
1228 Tab,
1229 Underline,
1230 Unlabeled,
1231 VolumeDown,
1232 VolumeUp,
1233 Wake,
1234 WebBack,
1235 WebFavorites,
1236 WebForward,
1237 WebHome,
1238 WebRefresh,
1239 WebSearch,
1240 WebStop,
1241 Yen,
1242 Copy,
1243 Paste,
1244 Cut
1245}
1246
1247#[derive(Debug, Hash, PartialEq, Eq, Clone, Default)]
1249pub struct ModifiersState
1250{
1251 pub(crate) ctrl: bool,
1252 pub(crate) alt: bool,
1253 pub(crate) shift: bool,
1254 pub(crate) logo: bool
1255}
1256
1257impl ModifiersState
1258{
1259 #[inline]
1261 #[must_use]
1262 pub fn ctrl(&self) -> bool
1263 {
1264 self.ctrl
1265 }
1266
1267 #[inline]
1269 #[must_use]
1270 pub fn alt(&self) -> bool
1271 {
1272 self.alt
1273 }
1274
1275 #[inline]
1277 #[must_use]
1278 pub fn shift(&self) -> bool
1279 {
1280 self.shift
1281 }
1282
1283 #[inline]
1285 #[must_use]
1286 pub fn logo(&self) -> bool
1287 {
1288 self.logo
1289 }
1290}
1291
1292#[derive(Debug, PartialEq, Clone)]
1295pub(crate) enum WindowCreationMode
1296{
1297 Windowed
1299 {
1300 size: WindowSize,
1302
1303 position: Option<WindowPosition>
1305 },
1306
1307 FullscreenBorderless
1309}
1310
1311#[derive(Debug, PartialEq, Clone)]
1313pub enum WindowSize
1314{
1315 PhysicalPixels(UVec2),
1317 ScaledPixels(Vec2),
1319 MarginPhysicalPixels(u32),
1322 MarginScaledPixels(f32)
1325}
1326
1327#[derive(Debug, Hash, PartialEq, Eq, Clone)]
1329pub enum WindowPosition
1330{
1331 Center,
1333 CenterOnParent,
1339 PrimaryMonitorPixelsFromTopLeft(IVec2)
1342}
1343
1344#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
1346pub enum WindowFullscreenMode
1347{
1348 Windowed,
1350 FullscreenBorderless
1352}
1353
1354#[derive(Debug, Clone, PartialEq)]
1356pub struct WindowCreationOptions
1357{
1358 pub(crate) mode: WindowCreationMode,
1359 pub(crate) multisampling: u16,
1360 pub(crate) vsync: bool,
1361 pub(crate) always_on_top: bool,
1362 pub(crate) resizable: bool,
1363 pub(crate) minimizable: bool,
1364 pub(crate) maximizable: bool,
1365 pub(crate) maximized: bool,
1366 pub(crate) transparent: bool,
1367 pub(crate) decorations: bool,
1368 pub(crate) visible: bool,
1369 pub(crate) hide_on_close: bool
1370}
1371
1372impl WindowCreationOptions
1373{
1374 pub fn new_windowed(size: WindowSize, position: Option<WindowPosition>) -> Self
1377 {
1378 Self::new(WindowCreationMode::Windowed { size, position })
1379 }
1380
1381 #[inline]
1384 #[must_use]
1385 pub fn new_fullscreen_borderless() -> Self
1386 {
1387 Self::new(WindowCreationMode::FullscreenBorderless)
1388 }
1389
1390 #[inline]
1391 #[must_use]
1392 fn new(mode: WindowCreationMode) -> Self
1393 {
1394 WindowCreationOptions {
1395 mode,
1396 multisampling: 16,
1397 vsync: true,
1398 always_on_top: false,
1399 resizable: true,
1400 minimizable: true,
1401 maximizable: true,
1402 maximized: false,
1403 decorations: true,
1404 transparent: false,
1405 visible: true,
1406 hide_on_close: false
1407 }
1408 }
1409
1410 #[inline]
1416 #[must_use]
1417 pub fn with_multisampling(mut self, multisampling: u16) -> Self
1418 {
1419 self.multisampling = multisampling;
1420 self
1421 }
1422
1423 #[inline]
1429 #[must_use]
1430 pub fn with_vsync(mut self, vsync: bool) -> Self
1431 {
1432 self.vsync = vsync;
1433 self
1434 }
1435
1436 #[inline]
1439 #[must_use]
1440 pub fn with_resizable(mut self, resizable: bool) -> Self
1441 {
1442 self.resizable = resizable;
1443 self
1444 }
1445
1446 #[inline]
1452 #[must_use]
1453 pub fn with_minimizable(mut self, minimizable: bool) -> Self
1454 {
1455 self.minimizable = minimizable;
1456 self
1457 }
1458
1459 #[inline]
1466 #[must_use]
1467 pub fn with_maximizable(mut self, maximizable: bool) -> Self
1468 {
1469 self.maximizable = maximizable;
1470 self
1471 }
1472
1473 #[inline]
1476 #[must_use]
1477 pub fn with_always_on_top(mut self, always_on_top: bool) -> Self
1478 {
1479 self.always_on_top = always_on_top;
1480 self
1481 }
1482
1483 #[inline]
1486 #[must_use]
1487 pub fn with_maximized(mut self, maximized: bool) -> Self
1488 {
1489 self.maximized = maximized;
1490 self
1491 }
1492
1493 #[inline]
1496 #[must_use]
1497 pub fn with_decorations(mut self, decorations: bool) -> Self
1498 {
1499 self.decorations = decorations;
1500 self
1501 }
1502
1503 #[inline]
1509 #[must_use]
1510 pub fn with_transparent(mut self, transparent: bool) -> Self
1511 {
1512 self.transparent = transparent;
1513 self
1514 }
1515
1516 #[inline]
1523 #[must_use]
1524 pub fn with_visible(mut self, visible: bool) -> Self
1525 {
1526 self.visible = visible;
1527 self
1528 }
1529
1530 #[inline]
1542 #[must_use]
1543 pub fn with_hide_on_close(mut self, hide_on_close: bool) -> Self
1544 {
1545 self.hide_on_close = hide_on_close;
1546 self
1547 }
1548}
1549
1550pub type KeyScancode = u32;