Skip to content

Commit

Permalink
Code style regarding resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyfritz committed Jun 8, 2018
1 parent 1933165 commit dd1022a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
48 changes: 25 additions & 23 deletions examples/resizable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => return 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
});
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/platform/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd1022a

Please sign in to comment.