Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Added documentation to WindowMode to better document what 'use_size' … #3216

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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