Skip to content

Commit 353f2e0

Browse files
beerytmockersf
andauthored
Add documentation comments to bevy_winit (#8115)
# Objective - [x] Add documentation comments to `bevy_winit` - [x] Add `#![warn(missing_docs)]` to `bevy_winit`. Relates to #3492 --------- Co-authored-by: François <[email protected]>
1 parent 2d5ef75 commit 353f2e0

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

crates/bevy_winit/src/accessibility.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Helpers for mapping window entities to accessibility types
2+
13
use std::{
24
collections::VecDeque,
35
sync::{atomic::Ordering, Arc, Mutex},

crates/bevy_winit/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#![warn(missing_docs)]
2+
//! `bevy_winit` provides utilities to handle window creation and the eventloop through [`winit`]
3+
//!
4+
//! Most commonly, the [`WinitPlugin`] is used as part of
5+
//! [`DefaultPlugins`](https://docs.rs/bevy/latest/bevy/struct.DefaultPlugins.html).
6+
//! The app's [runner](bevy_app::App::runner) is set by `WinitPlugin` and handles the `winit` [`EventLoop`](winit::event_loop::EventLoop).
7+
//! See `winit_runner` for details.
8+
19
pub mod accessibility;
210
mod converters;
311
mod system;
@@ -49,6 +57,7 @@ use crate::web_resize::{CanvasParentResizeEventChannel, CanvasParentResizePlugin
4957
#[cfg(target_os = "android")]
5058
pub static ANDROID_APP: once_cell::sync::OnceCell<AndroidApp> = once_cell::sync::OnceCell::new();
5159

60+
/// A [`Plugin`] that utilizes [`winit`] for window creation and event loop management.
5261
#[derive(Default)]
5362
pub struct WinitPlugin;
5463

@@ -270,6 +279,9 @@ impl Default for WinitPersistentState {
270279
}
271280
}
272281

282+
/// The default [`App::runner`] for the [`WinitPlugin`] plugin.
283+
///
284+
/// Overriding the app's [runner](bevy_app::App::runner) while using `WinitPlugin` will bypass the `EventLoop`.
273285
pub fn winit_runner(mut app: App) {
274286
// We remove this so that we have ownership over it.
275287
let mut event_loop = app

crates/bevy_winit/src/winit_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy_ecs::system::Resource;
22
use bevy_utils::Duration;
33

4-
/// A resource for configuring usage of the `rust_winit` library.
4+
/// A resource for configuring usage of the [`winit`] library.
55
#[derive(Debug, Resource)]
66
pub struct WinitSettings {
77
/// Configures `winit` to return control to the caller after exiting the

crates/bevy_winit/src/winit_windows.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![warn(missing_docs)]
12
use std::sync::atomic::Ordering;
23

34
use accesskit_winit::Adapter;
@@ -20,18 +21,24 @@ use crate::{
2021
converters::convert_window_level,
2122
};
2223

24+
/// A resource which maps window entities to [`winit`] library windows.
2325
#[derive(Debug, Default)]
2426
pub struct WinitWindows {
27+
/// Stores [`winit`] windows by window identifier.
2528
pub windows: HashMap<winit::window::WindowId, winit::window::Window>,
29+
/// Maps entities to `winit` window identifiers.
2630
pub entity_to_winit: HashMap<Entity, winit::window::WindowId>,
31+
/// Maps `winit` window identifiers to entities.
2732
pub winit_to_entity: HashMap<winit::window::WindowId, Entity>,
33+
2834
// Some winit functions, such as `set_window_icon` can only be used from the main thread. If
2935
// they are used in another thread, the app will hang. This marker ensures `WinitWindows` is
3036
// only ever accessed with bevy's non-send functions and in NonSend systems.
3137
_not_send_sync: core::marker::PhantomData<*const ()>,
3238
}
3339

3440
impl WinitWindows {
41+
/// Creates a `winit` window and associates it with our entity.
3542
pub fn create_window(
3643
&mut self,
3744
event_loop: &winit::event_loop::EventLoopWindowTarget<()>,
@@ -227,6 +234,9 @@ impl WinitWindows {
227234
}
228235
}
229236

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.
230240
pub fn get_fitting_videomode(
231241
monitor: &winit::monitor::MonitorHandle,
232242
width: u32,
@@ -259,6 +269,9 @@ pub fn get_fitting_videomode(
259269
modes.first().unwrap().clone()
260270
}
261271

272+
/// Gets the "best" videomode from a monitor.
273+
///
274+
/// The heuristic for "best" prioritizes width, height, and refresh rate in that order.
262275
pub fn get_best_videomode(monitor: &winit::monitor::MonitorHandle) -> winit::monitor::VideoMode {
263276
let mut modes = monitor.video_modes().collect::<Vec<_>>();
264277
modes.sort_by(|a, b| {
@@ -300,6 +313,7 @@ pub(crate) fn attempt_grab(winit_window: &winit::window::Window, grab_mode: Curs
300313
}
301314
}
302315

316+
/// Compute the physical window position for a given [`WindowPosition`].
303317
// Ideally we could generify this across window backends, but we only really have winit atm
304318
// so whatever.
305319
pub fn winit_window_position(

0 commit comments

Comments
 (0)