Skip to content

Commit

Permalink
improve documentation relating to WindowPlugin and Window (#9173)
Browse files Browse the repository at this point in the history
- attempt to clarify with better docstrings the default behaviour of
WindowPlugin and the component type it accepts.

# Objective

- I'm new to Rust and Bevy, I got a bit confused about how to customise
some window parameters (title, height, width etc) and while the docs do
show the struct code for that field `Option<Window>` I was a bit of a
doofus and skipped that to read the docstring entry for `primary_window`
and then the `Window` component directly which aren't linked together.
This is a minor improvement which I think will help in-case others, like
me, have a doofus moment.

---------

Co-authored-by: Sélène Amanita <134181069+Selene-Amanita@users.noreply.github.com>
  • Loading branch information
tsujp and Selene-Amanita authored Jul 30, 2023
1 parent e02938f commit 04ca832
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 8 additions & 5 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ impl Default for WindowPlugin {

/// A [`Plugin`] that defines an interface for windowing support in Bevy.
pub struct WindowPlugin {
/// Settings for the primary window. This will be spawned by
/// default, with the marker component [`PrimaryWindow`](PrimaryWindow).
/// If you want to run without a primary window you should set this to `None`.
/// Settings for the primary window.
///
/// Note that if there are no windows, by default the App will exit,
/// due to [`exit_on_all_closed`].
/// `Some(custom_window)` will spawn an entity with `custom_window` and [`PrimaryWindow`] as components.
/// `None` will not spawn a primary window.
///
/// Defaults to `Some(Window::default())`.
///
/// Note that if there are no windows the App will exit (by default) due to
/// [`exit_on_all_closed`].
pub primary_window: Option<Window>,

/// Whether to exit the app when there are no open windows.
Expand Down
13 changes: 7 additions & 6 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use crate::CursorIcon;
///
/// Currently this is assumed to only exist on 1 entity at a time.
///
/// [`WindowPlugin`](crate::WindowPlugin) will spawn a window entity
/// with this component if `primary_window` is `Some`.
/// [`WindowPlugin`](crate::WindowPlugin) will spawn a [`Window`] entity
/// with this component if [`primary_window`](crate::WindowPlugin::primary_window)
/// is `Some`.
#[derive(Default, Debug, Component, PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Reflect)]
#[reflect(Component)]
pub struct PrimaryWindow;
Expand Down Expand Up @@ -243,16 +244,16 @@ impl Default for Window {
}

impl Window {
/// Setting this to true will attempt to maximize the window.
/// Setting to true will attempt to maximize the window.
///
/// Setting it to false will attempt to un-maximize the window.
/// Setting to false will attempt to un-maximize the window.
pub fn set_maximized(&mut self, maximized: bool) {
self.internal.maximize_request = Some(maximized);
}

/// Setting this to true will attempt to minimize the window.
/// Setting to true will attempt to minimize the window.
///
/// Setting it to false will attempt to un-minimize the window.
/// Setting to false will attempt to un-minimize the window.
pub fn set_minimized(&mut self, minimized: bool) {
self.internal.minimize_request = Some(minimized);
}
Expand Down

0 comments on commit 04ca832

Please sign in to comment.