From bab4ee962d88a5576d7f045d22129e8d20645f14 Mon Sep 17 00:00:00 2001 From: Dimitri Bobkov Date: Tue, 30 Nov 2021 23:51:11 +0000 Subject: [PATCH] =?UTF-8?q?Added=20documentation=20to=20WindowMode=20to=20?= =?UTF-8?q?better=20document=20what=20'use=5Fsize'=20=E2=80=A6=20(#3216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- crates/bevy_window/src/window.rs | 12 +++++++----- crates/bevy_winit/src/lib.rs | 22 ++++++++++++---------- crates/bevy_winit/src/winit_windows.rs | 21 ++++++++++++--------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index a7a497ff65ab6..a9aa5844ad2af 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -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 { diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 7e47c0022230b..e2596e1f227ee 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -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), } } diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 86ca6d3d436d6..81dc6f537f9c5 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -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 { @@ -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,