Skip to content

Commit

Permalink
Added documentation to WindowMode to better document what 'use_size' … (
Browse files Browse the repository at this point in the history
#3216)

This pull request aims to solve the issue of a lack of documentation in the enum WindowMode

# Objective

- Fixes #3136

## Solution

- Added a few lines of documentation that should document what the enum does better
  • Loading branch information
dimitri-br committed Nov 30, 2021
1 parent d59a3dd commit bab4ee9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
12 changes: 7 additions & 5 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,17 @@ pub enum WindowCommand {
}

/// Defines the way a window is displayed
/// The use_size option that is used in the Fullscreen variant
/// defines whether a videomode is chosen that best fits the width and height
/// in the Window structure, or if these are ignored.
/// E.g. when use_size is set to false the best video mode possible is chosen.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum WindowMode {
/// Creates a window that uses the given size
Windowed,
/// Creates a borderless window that uses the full size of the screen
BorderlessFullscreen,
Fullscreen { use_size: bool },
/// Creates a fullscreen window that will render at desktop resolution. The app will use the closest supported size
/// from the given size and scale it to fit the screen.
SizedFullscreen,
/// Creates a fullscreen window that uses the maximum supported size
Fullscreen,
}

impl Window {
Expand Down
22 changes: 12 additions & 10 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ fn change_window(world: &mut World) {
bevy_window::WindowMode::BorderlessFullscreen => {
window.set_fullscreen(Some(winit::window::Fullscreen::Borderless(None)))
}
bevy_window::WindowMode::Fullscreen { use_size } => window.set_fullscreen(
Some(winit::window::Fullscreen::Exclusive(match use_size {
true => get_fitting_videomode(
&window.current_monitor().unwrap(),
width,
height,
),
false => get_best_videomode(&window.current_monitor().unwrap()),
})),
),
bevy_window::WindowMode::Fullscreen => {
window.set_fullscreen(Some(winit::window::Fullscreen::Exclusive(
get_best_videomode(&window.current_monitor().unwrap()),
)))
}
bevy_window::WindowMode::SizedFullscreen => window.set_fullscreen(Some(
winit::window::Fullscreen::Exclusive(get_fitting_videomode(
&window.current_monitor().unwrap(),
width,
height,
)),
)),
bevy_window::WindowMode::Windowed => window.set_fullscreen(None),
}
}
Expand Down
21 changes: 12 additions & 9 deletions crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ impl WinitWindows {
WindowMode::BorderlessFullscreen => winit_window_builder.with_fullscreen(Some(
winit::window::Fullscreen::Borderless(event_loop.primary_monitor()),
)),
WindowMode::Fullscreen { use_size } => winit_window_builder.with_fullscreen(Some(
winit::window::Fullscreen::Exclusive(match use_size {
true => get_fitting_videomode(
&event_loop.primary_monitor().unwrap(),
window_descriptor.width as u32,
window_descriptor.height as u32,
),
false => get_best_videomode(&event_loop.primary_monitor().unwrap()),
}),
WindowMode::Fullscreen => {
winit_window_builder.with_fullscreen(Some(winit::window::Fullscreen::Exclusive(
get_best_videomode(&event_loop.primary_monitor().unwrap()),
)))
}
WindowMode::SizedFullscreen => winit_window_builder.with_fullscreen(Some(
winit::window::Fullscreen::Exclusive(get_fitting_videomode(
&event_loop.primary_monitor().unwrap(),
window_descriptor.width as u32,
window_descriptor.height as u32,
)),
)),
_ => {
let WindowDescriptor {
Expand Down Expand Up @@ -180,6 +182,7 @@ impl WinitWindows {
self.winit_to_window_id.get(&id).cloned()
}
}

pub fn get_fitting_videomode(
monitor: &winit::monitor::MonitorHandle,
width: u32,
Expand Down

0 comments on commit bab4ee9

Please sign in to comment.