From cbeaa71eaa9d45bb8921a2ba86855b0fd69aa611 Mon Sep 17 00:00:00 2001 From: Danny Fritz Date: Fri, 8 Jun 2018 14:39:38 -0600 Subject: [PATCH] Code style regarding resizable --- CHANGELOG.md | 2 +- examples/resizable.rs | 48 +++++++++++++++++--------------- src/lib.rs | 2 +- src/platform/linux/mod.rs | 3 +- src/platform/linux/x11/window.rs | 6 ++-- src/platform/windows/window.rs | 5 ++-- src/window.rs | 6 ++-- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af2a2060433..9996049e8e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ - On X11, the `Moved` event is no longer sent when the window is resized without changing position. - `MouseCursor` and `CursorState` now implement `Default`. - `WindowBuilder::with_resizable` implemented for Windows, X11, and macOS. -- `Window::set_resizable` implemented for MacOS, X11, and Windows. +- `Window::set_resizable` implemented for Windows, X11, and macOS. - On X11, if the monitor's width or height in millimeters is reported as 0, the DPI is now 1.0 instead of +inf. - On X11, the environment variable `WINIT_HIDPI_FACTOR` has been added for overriding DPI factor. - On X11, enabling transparency no longer causes the window contents to flicker when resizing. diff --git a/examples/resizable.rs b/examples/resizable.rs index 6b445e9cb28..4c5a615fd29 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -3,34 +3,36 @@ extern crate winit; fn main() { let mut events_loop = winit::EventsLoop::new(); + let mut resizable = false; + let window = winit::WindowBuilder::new() .with_title("Hit space to toggle resizability.") .with_dimensions(400, 200) - .with_resizable(false) + .with_resizable(resizable) .build(&events_loop) .unwrap(); - let mut resizable = false; - - events_loop.run_forever(|event| match event { - winit::Event::WindowEvent { event, .. } => match event { - winit::WindowEvent::CloseRequested => winit::ControlFlow::Break, - winit::WindowEvent::KeyboardInput { - input: - winit::KeyboardInput { - virtual_keycode: Some(winit::VirtualKeyCode::Space), - state: winit::ElementState::Released, - .. - }, - .. - } => { - resizable = !resizable; - println!("Resizable: {}", resizable); - window.set_resizable(resizable); - winit::ControlFlow::Continue - } - _ => winit::ControlFlow::Continue, - }, - _ => winit::ControlFlow::Continue, + events_loop.run_forever(|event| { + match event { + winit::Event::WindowEvent { event, .. } => match event { + winit::WindowEvent::CloseRequested => winit::ControlFlow::Break, + winit::WindowEvent::KeyboardInput { + input: + winit::KeyboardInput { + virtual_keycode: Some(winit::VirtualKeyCode::Space), + state: winit::ElementState::Released, + .. + }, + .. + } => { + resizable = !resizable; + println!("Resizable: {}", resizable); + window.set_resizable(resizable); + } + _ => (), + }, + _ => (), + }; + winit::ControlFlow::Continue }); } diff --git a/src/lib.rs b/src/lib.rs index 24ea46b5bed..5a324333957 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -422,7 +422,7 @@ pub struct WindowAttributes { /// The default is `None`. pub max_dimensions: Option<(u32, u32)>, - /// [Windows, MacOS, and X11 only] Whether the window is resizable or not + /// Whether the window is resizable or not. /// /// The default is `true`. pub resizable: bool, diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 562a8e11deb..686ec46586f 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -237,8 +237,7 @@ impl Window { pub fn set_resizable(&self, resizable: bool) { match self { &Window::X(ref w) => w.set_resizable(resizable), - // &Window::Wayland(ref w) => w.set_resizable(resizable), - _ => {} + &Window::Wayland(ref _w) => unimplemented!(), } } diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index 627e75d75fe..5484ab6aae2 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -730,11 +730,9 @@ impl UnownedWindow { unsafe { self.update_normal_hints(|size_hints| { if resizable { - (*size_hints).flags &= !ffi::PMinSize; - (*size_hints).flags &= !ffi::PMaxSize; + (*size_hints).flags &= !(ffi::PMinSize & ffi::PMaxSize); } else { - (*size_hints).flags |= ffi::PMinSize; - (*size_hints).flags |= ffi::PMaxSize; + (*size_hints).flags |= ffi::PMinSize & ffi::PMaxSize; if let Some((width, height)) = self.get_inner_size() { (*size_hints).min_width = width as c_int; (*size_hints).min_height = height as c_int; diff --git a/src/platform/windows/window.rs b/src/platform/windows/window.rs index 5f05889496c..b7b03d97639 100644 --- a/src/platform/windows/window.rs +++ b/src/platform/windows/window.rs @@ -240,7 +240,6 @@ impl Window { } } - /// See the docs in the crate root file. #[inline] pub fn set_resizable(&self, resizable: bool) { if let Ok(mut window_state) = self.window_state.lock() { @@ -252,9 +251,9 @@ impl Window { winuser::GetWindowLongW(self.window.0, winuser::GWL_STYLE) }; if resizable { - style |= winuser::WS_SIZEBOX as i32; + style |= winuser::WS_SIZEBOX as LONG; } else { - style &= !winuser::WS_SIZEBOX as i32; + style &= !winuser::WS_SIZEBOX as LONG; } unsafe { winuser::SetWindowLongW( diff --git a/src/window.rs b/src/window.rs index e6743fb4737..b804220cdc5 100644 --- a/src/window.rs +++ b/src/window.rs @@ -317,15 +317,17 @@ impl Window { self.window.set_max_dimensions(dimensions) } + /* /// Sets whether the window is resizable or not. /// /// ## Platform-specific /// - /// This only has an effect on Windows, X11, and MacOS. - #[inline] + /// This only has an effect on Windows, X11, and macOS. + #[inline] pub fn set_resizable(&self, resizable: bool) { self.window.set_resizable(resizable) } + */ /// DEPRECATED. Gets the native platform specific display for this window. /// This is typically only required when integrating with