Skip to content

Commit

Permalink
macOS: Implement with_resize_increments
Browse files Browse the repository at this point in the history
  • Loading branch information
francesca64 committed May 15, 2018
1 parent d86f53a commit 16c949c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Cargo.lock
target/
rls/
*~
#*#
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- On X11, `Window::hidpi_factor` returns values from XRandR rather than the inaccurate values previously queried from the core protocol.
- On X11, the primary monitor is detected correctly even when using versions of XRandR less than 1.5.
- `MonitorId` now implements `Debug`.
- Added `WindowBuilderExt::with_resize_increments` to macOS.
- **Breaking:** On X11, `WindowBuilderExt::with_resize_increments` and `WindowBuilderExt::with_base_size` now take `u32` values rather than `i32`.

# Version 0.14.0 (2018-05-09)

Expand Down
8 changes: 8 additions & 0 deletions src/os/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub trait WindowBuilderExt {
fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder;
fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder;
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
/// Build window with `resizeIncrements` property.
fn with_resize_increments(self, width_inc: u32, height_inc: u32) -> WindowBuilder;
}

impl WindowBuilderExt for WindowBuilder {
Expand Down Expand Up @@ -129,6 +131,12 @@ impl WindowBuilderExt for WindowBuilder {
self.platform_specific.fullsize_content_view = fullsize_content_view;
self
}

#[inline]
fn with_resize_increments(mut self, width_inc: u32, height_inc: u32) -> WindowBuilder {
self.platform_specific.resize_increments = Some((width_inc, height_inc));
self
}
}

/// Additional methods on `MonitorId` that are specific to MacOS.
Expand Down
4 changes: 2 additions & 2 deletions src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ impl WindowBuilderExt for WindowBuilder {
}

#[inline]
fn with_resize_increments(mut self, width_inc: i32, height_inc: i32) -> WindowBuilder {
fn with_resize_increments(mut self, width_inc: u32, height_inc: u32) -> WindowBuilder {
self.platform_specific.resize_increments = Some((width_inc, height_inc));
self
}

#[inline]
fn with_base_size(mut self, base_width: i32, base_height: i32) -> WindowBuilder {
fn with_base_size(mut self, base_width: u32, base_height: u32) -> WindowBuilder {
self.platform_specific.base_size = Some((base_width, base_height));
self
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const BACKEND_PREFERENCE_ENV_VAR: &str = "WINIT_UNIX_BACKEND";
pub struct PlatformSpecificWindowBuilderAttributes {
pub visual_infos: Option<XVisualInfo>,
pub screen_id: Option<i32>,
pub resize_increments: Option<(i32, i32)>,
pub base_size: Option<(i32, i32)>,
pub resize_increments: Option<(u32, u32)>,
pub base_size: Option<(u32, u32)>,
}

lazy_static!(
Expand Down
8 changes: 8 additions & 0 deletions src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub titlebar_hidden: bool,
pub titlebar_buttons_hidden: bool,
pub fullsize_content_view: bool,
pub resize_increments: Option<(u32, u32)>,
}

pub struct Window2 {
Expand Down Expand Up @@ -777,6 +778,13 @@ impl Window2 {
if pl_attrs.movable_by_window_background {
window.setMovableByWindowBackground_(YES);
}

if let Some((x, y)) = pl_attrs.resize_increments {
if x >= 1 && y >= 1 {
let size = NSSize::new(x as _, y as _);
window.setResizeIncrements_(size);
}
}

if !attrs.decorations {
window.setTitleVisibility_(appkit::NSWindowTitleVisibility::NSWindowTitleHidden);
Expand Down

0 comments on commit 16c949c

Please sign in to comment.