From 58a00bffbbd8b6e4a659e3dcafc433957414c906 Mon Sep 17 00:00:00 2001 From: Danny Fritz Date: Sat, 2 Jun 2018 08:51:24 -0600 Subject: [PATCH] Windows: implement with_resizable (#540) (#541) * Windows: implement with_resizable (#540) * Fixed typo --- CHANGELOG.md | 1 + examples/no_resize.rs | 24 ++++++++++++++++++++++++ src/lib.rs | 6 ++++++ src/platform/windows/window.rs | 4 ++++ src/window.rs | 11 +++++++++++ 5 files changed, 46 insertions(+) create mode 100644 examples/no_resize.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 15fc634f..87df57b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,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. # Version 0.15.0 (2018-05-22) diff --git a/examples/no_resize.rs b/examples/no_resize.rs new file mode 100644 index 00000000..bc357e86 --- /dev/null +++ b/examples/no_resize.rs @@ -0,0 +1,24 @@ +extern crate winit; + +fn main() { + let mut events_loop = winit::EventsLoop::new(); + + let _window = winit::WindowBuilder::new() + .with_title("A non-resizable window!") + .with_dimensions(200, 200) + .with_resizable(false) + .build(&events_loop) + .unwrap(); + + events_loop.run_forever(|event| { + println!("{:?}", event); + + match event { + winit::Event::WindowEvent { + event: winit::WindowEvent::CloseRequested, + .. + } => winit::ControlFlow::Break, + _ => winit::ControlFlow::Continue, + } + }); +} diff --git a/src/lib.rs b/src/lib.rs index b4120d75..479c0dd5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -422,6 +422,11 @@ pub struct WindowAttributes { /// The default is `None`. pub max_dimensions: Option<(u32, u32)>, + /// [Windows only] Whether the window is resizable or not + /// + /// The default is `true`. + pub resizable: bool, + /// Whether the window should be set as fullscreen upon creation. /// /// The default is `None`. @@ -475,6 +480,7 @@ impl Default for WindowAttributes { dimensions: None, min_dimensions: None, max_dimensions: None, + resizable: true, title: "winit window".to_owned(), maximized: false, fullscreen: None, diff --git a/src/platform/windows/window.rs b/src/platform/windows/window.rs index 93fce9fe..5c8987a2 100644 --- a/src/platform/windows/window.rs +++ b/src/platform/windows/window.rs @@ -843,6 +843,10 @@ unsafe fn init( style | winuser::WS_VISIBLE }; + if !window.resizable { + style &= !winuser::WS_SIZEBOX; + } + if pl_attribs.parent.is_some() { style |= winuser::WS_CHILD; } diff --git a/src/window.rs b/src/window.rs index cae1f239..1568306c 100644 --- a/src/window.rs +++ b/src/window.rs @@ -49,6 +49,17 @@ impl WindowBuilder { self } + /// Sets whether the window is resizable or not + /// + /// ## Platform-specific + /// + /// This only has an effect on Windows. + #[inline] + pub fn with_resizable(mut self, resizable: bool) -> WindowBuilder { + self.window.resizable = resizable; + self + } + /// Requests a specific title for the window. #[inline] pub fn with_title>(mut self, title: T) -> WindowBuilder {