1
+ #![ warn( missing_docs) ]
1
2
use std:: sync:: atomic:: Ordering ;
2
3
3
4
use accesskit_winit:: Adapter ;
@@ -20,18 +21,24 @@ use crate::{
20
21
converters:: convert_window_level,
21
22
} ;
22
23
24
+ /// A resource which maps window entities to [`winit`] library windows.
23
25
#[ derive( Debug , Default ) ]
24
26
pub struct WinitWindows {
27
+ /// Stores [`winit`] windows by window identifier.
25
28
pub windows : HashMap < winit:: window:: WindowId , winit:: window:: Window > ,
29
+ /// Maps entities to `winit` window identifiers.
26
30
pub entity_to_winit : HashMap < Entity , winit:: window:: WindowId > ,
31
+ /// Maps `winit` window identifiers to entities.
27
32
pub winit_to_entity : HashMap < winit:: window:: WindowId , Entity > ,
33
+
28
34
// Some winit functions, such as `set_window_icon` can only be used from the main thread. If
29
35
// they are used in another thread, the app will hang. This marker ensures `WinitWindows` is
30
36
// only ever accessed with bevy's non-send functions and in NonSend systems.
31
37
_not_send_sync : core:: marker:: PhantomData < * const ( ) > ,
32
38
}
33
39
34
40
impl WinitWindows {
41
+ /// Creates a `winit` window and associates it with our entity.
35
42
pub fn create_window (
36
43
& mut self ,
37
44
event_loop : & winit:: event_loop:: EventLoopWindowTarget < ( ) > ,
@@ -227,6 +234,9 @@ impl WinitWindows {
227
234
}
228
235
}
229
236
237
+ /// Gets the "best" video mode which fits the given dimensions.
238
+ ///
239
+ /// The heuristic for "best" prioritizes width, height, and refresh rate in that order.
230
240
pub fn get_fitting_videomode (
231
241
monitor : & winit:: monitor:: MonitorHandle ,
232
242
width : u32 ,
@@ -259,6 +269,9 @@ pub fn get_fitting_videomode(
259
269
modes. first ( ) . unwrap ( ) . clone ( )
260
270
}
261
271
272
+ /// Gets the "best" videomode from a monitor.
273
+ ///
274
+ /// The heuristic for "best" prioritizes width, height, and refresh rate in that order.
262
275
pub fn get_best_videomode ( monitor : & winit:: monitor:: MonitorHandle ) -> winit:: monitor:: VideoMode {
263
276
let mut modes = monitor. video_modes ( ) . collect :: < Vec < _ > > ( ) ;
264
277
modes. sort_by ( |a, b| {
@@ -300,6 +313,7 @@ pub(crate) fn attempt_grab(winit_window: &winit::window::Window, grab_mode: Curs
300
313
}
301
314
}
302
315
316
+ /// Compute the physical window position for a given [`WindowPosition`].
303
317
// Ideally we could generify this across window backends, but we only really have winit atm
304
318
// so whatever.
305
319
pub fn winit_window_position (
0 commit comments