Add Window::is_maximized method (#1804)

This commit is contained in:
Simas Toleikis 2021-01-27 20:01:17 +02:00 committed by GitHub
parent 05125029c6
commit 3f1e09ec0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 49 additions and 7 deletions

View file

@ -1,5 +1,6 @@
# Unreleased # Unreleased
- Added `is_maximized` method to `Window`.
- On Windows, fix bug causing newly created windows to erroneously display the "wait" (spinning) cursor. - On Windows, fix bug causing newly created windows to erroneously display the "wait" (spinning) cursor.
- On Windows, change the default window size (1024x768) to match the default on other desktop platforms (800x600). - On Windows, change the default window size (1024x768) to match the default on other desktop platforms (800x600).
- On Windows, fix bug causing mouse capture to not be released. - On Windows, fix bug causing mouse capture to not be released.

View file

@ -23,7 +23,6 @@ fn main() {
_ => panic!("Please enter a valid number"), _ => panic!("Please enter a valid number"),
}); });
let mut is_maximized = false;
let mut decorations = true; let mut decorations = true;
let window = WindowBuilder::new() let window = WindowBuilder::new()
@ -59,8 +58,8 @@ fn main() {
println!("window.fullscreen {:?}", window.fullscreen()); println!("window.fullscreen {:?}", window.fullscreen());
} }
(VirtualKeyCode::M, ElementState::Pressed) => { (VirtualKeyCode::M, ElementState::Pressed) => {
is_maximized = !is_maximized; let is_maximized = window.is_maximized();
window.set_maximized(is_maximized); window.set_maximized(!is_maximized);
} }
(VirtualKeyCode::D, ElementState::Pressed) => { (VirtualKeyCode::D, ElementState::Pressed) => {
decorations = !decorations; decorations = !decorations;

View file

@ -28,7 +28,6 @@ fn main() {
eprintln!(" (X) Toggle maximized"); eprintln!(" (X) Toggle maximized");
let mut minimized = false; let mut minimized = false;
let mut maximized = false;
let mut visible = true; let mut visible = true;
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
@ -109,8 +108,8 @@ fn main() {
window.set_visible(visible); window.set_visible(visible);
} }
VirtualKeyCode::X => { VirtualKeyCode::X => {
maximized = !maximized; let is_maximized = window.is_maximized();
window.set_maximized(maximized); window.set_maximized(!is_maximized);
} }
_ => (), _ => (),
}, },

View file

@ -496,6 +496,10 @@ impl Window {
pub fn set_maximized(&self, _maximized: bool) {} pub fn set_maximized(&self, _maximized: bool) {}
pub fn is_maximized(&self) -> bool {
false
}
pub fn set_fullscreen(&self, _monitor: Option<window::Fullscreen>) { pub fn set_fullscreen(&self, _monitor: Option<window::Fullscreen>) {
warn!("Cannot set fullscreen on Android"); warn!("Cannot set fullscreen on Android");
} }

View file

@ -190,6 +190,11 @@ impl Inner {
warn!("`Window::set_maximized` is ignored on iOS") warn!("`Window::set_maximized` is ignored on iOS")
} }
pub fn is_maximized(&self) -> bool {
warn!("`Window::is_maximized` is ignored on iOS");
false
}
pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) { pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) {
unsafe { unsafe {
let uiscreen = match monitor { let uiscreen = match monitor {

View file

@ -373,6 +373,12 @@ impl Window {
x11_or_wayland!(match self; Window(w) => w.set_maximized(maximized)) x11_or_wayland!(match self; Window(w) => w.set_maximized(maximized))
} }
#[inline]
pub fn is_maximized(&self) -> bool {
// TODO: Not implemented
false
}
#[inline] #[inline]
pub fn set_minimized(&self, minimized: bool) { pub fn set_minimized(&self, minimized: bool) {
x11_or_wayland!(match self; Window(w) => w.set_minimized(minimized)) x11_or_wayland!(match self; Window(w) => w.set_minimized(minimized))

View file

@ -730,6 +730,11 @@ impl UnownedWindow {
shared_state_lock.fullscreen.clone() shared_state_lock.fullscreen.clone()
} }
#[inline]
pub fn is_maximized(&self) -> bool {
self.is_zoomed()
}
#[inline] #[inline]
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) { pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
trace!("Locked shared state in `set_fullscreen`"); trace!("Locked shared state in `set_fullscreen`");

View file

@ -232,6 +232,12 @@ impl Window {
// Intentionally a no-op, as canvases cannot be 'maximized' // Intentionally a no-op, as canvases cannot be 'maximized'
} }
#[inline]
pub fn is_maximized(&self) -> bool {
// Canvas cannot be 'maximized'
false
}
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub fn fullscreen(&self) -> Option<Fullscreen> {
if self.canvas.borrow().is_fullscreen() { if self.canvas.borrow().is_fullscreen() {

View file

@ -385,6 +385,12 @@ impl Window {
}); });
} }
#[inline]
pub fn is_maximized(&self) -> bool {
let window_state = self.window_state.lock();
window_state.window_flags.contains(WindowFlags::MAXIMIZED)
}
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub fn fullscreen(&self) -> Option<Fullscreen> {
let window_state = self.window_state.lock(); let window_state = self.window_state.lock();

View file

@ -34,7 +34,7 @@ pub struct WindowState {
pub current_theme: Theme, pub current_theme: Theme,
pub preferred_theme: Option<Theme>, pub preferred_theme: Option<Theme>,
pub high_surrogate: Option<u16>, pub high_surrogate: Option<u16>,
window_flags: WindowFlags, pub window_flags: WindowFlags,
} }
#[derive(Clone)] #[derive(Clone)]

View file

@ -597,6 +597,17 @@ impl Window {
self.window.set_maximized(maximized) self.window.set_maximized(maximized)
} }
/// Gets the window's current maximized state.
///
/// ## Platform-specific
///
/// - **Wayland / X11:** Not implemented.
/// - **iOS / Android / Web:** Unsupported.
#[inline]
pub fn is_maximized(&self) -> bool {
self.window.is_maximized()
}
/// Sets the window to fullscreen or back. /// Sets the window to fullscreen or back.
/// ///
/// ## Platform-specific /// ## Platform-specific