From 1398d7833007e85198cfd35d5fabc70b51b4db31 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 4 Dec 2020 17:31:17 -0500 Subject: [PATCH] Allow windows to maximized. (#1004) Adds a new `set_maximized` method to allow users to maximize windows. --- crates/bevy_window/src/window.rs | 9 +++++++++ crates/bevy_winit/src/lib.rs | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index ac0fce771a..c1d1465788 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -82,6 +82,9 @@ pub enum WindowCommand { SetCursorPosition { position: Vec2, }, + SetMaximized { + maximized: bool, + }, } /// Defines the way a window is displayed @@ -140,6 +143,12 @@ impl Window { self.height } + #[inline] + pub fn set_maximized(&mut self, maximized: bool) { + self.command_queue + .push(WindowCommand::SetMaximized { maximized }); + } + pub fn set_resolution(&mut self, width: u32, height: u32) { self.width = width; self.height = height; diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index ca1a328c49..62a9cda2c2 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -104,6 +104,10 @@ fn change_window(_: &mut World, resources: &mut Resources) { )) .unwrap_or_else(|e| error!("Unable to set cursor position: {}", e)); } + bevy_window::WindowCommand::SetMaximized { maximized } => { + let window = winit_windows.get_window(id).unwrap(); + window.set_maximized(maximized) + } } } }