macOS: Implement with_resize_increments (#519)

Fixes #135
This commit is contained in:
Francesca Frangipane 2018-05-16 10:16:36 -04:00 committed by GitHub
parent 2464a135b3
commit 8440091a4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 13 deletions

View file

@ -11,6 +11,8 @@
- Fixed bug on macOS where using `with_decorations(false)` would cause `set_decorations(true)` to produce a transparent titlebar with no title. - Fixed bug on macOS where using `with_decorations(false)` would cause `set_decorations(true)` to produce a transparent titlebar with no title.
- Implemented `MonitorId::get_position` on macOS. - Implemented `MonitorId::get_position` on macOS.
- On macOS, `Window::get_current_monitor` now returns accurate values. - On macOS, `Window::get_current_monitor` now returns accurate values.
- 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) # Version 0.14.0 (2018-05-09)

View file

@ -71,64 +71,72 @@ impl From<ActivationPolicy> for NSApplicationActivationPolicy {
/// - `with_titlebar_buttons_hidden` /// - `with_titlebar_buttons_hidden`
/// - `with_fullsize_content_view` /// - `with_fullsize_content_view`
pub trait WindowBuilderExt { pub trait WindowBuilderExt {
/// Sets the activation policy for the window being built.
fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder; fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder;
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
fn with_movable_by_window_background(self, movable_by_window_background: bool) -> WindowBuilder; fn with_movable_by_window_background(self, movable_by_window_background: bool) -> WindowBuilder;
/// Makes the titlebar transparent and allows the content to appear behind it.
fn with_titlebar_transparent(self, titlebar_transparent: bool) -> WindowBuilder; fn with_titlebar_transparent(self, titlebar_transparent: bool) -> WindowBuilder;
/// Hides the window title.
fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder; fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder;
/// Hides the window titlebar.
fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder; fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder;
/// Hides the window titlebar buttons.
fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder; fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder;
/// Makes the window content appear behind the titlebar.
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder; fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
/// Build window with `resizeIncrements` property. Values must not be 0.
fn with_resize_increments(self, width_inc: u32, height_inc: u32) -> WindowBuilder;
} }
impl WindowBuilderExt for WindowBuilder { impl WindowBuilderExt for WindowBuilder {
/// Sets the activation policy for the window being built
#[inline] #[inline]
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder { fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder {
self.platform_specific.activation_policy = activation_policy; self.platform_specific.activation_policy = activation_policy;
self self
} }
/// Enables click-and-drag behavior for the entire window, not just the titlebar
#[inline] #[inline]
fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> WindowBuilder { fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> WindowBuilder {
self.platform_specific.movable_by_window_background = movable_by_window_background; self.platform_specific.movable_by_window_background = movable_by_window_background;
self self
} }
/// Makes the titlebar transparent and allows the content to appear behind it
#[inline] #[inline]
fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> WindowBuilder { fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> WindowBuilder {
self.platform_specific.titlebar_transparent = titlebar_transparent; self.platform_specific.titlebar_transparent = titlebar_transparent;
self self
} }
/// Hides the window titlebar
#[inline] #[inline]
fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder { fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder {
self.platform_specific.titlebar_hidden = titlebar_hidden; self.platform_specific.titlebar_hidden = titlebar_hidden;
self self
} }
/// Hides the window titlebar buttons
#[inline] #[inline]
fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder { fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder {
self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden; self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden;
self self
} }
/// Hides the window title
#[inline] #[inline]
fn with_title_hidden(mut self, title_hidden: bool) -> WindowBuilder { fn with_title_hidden(mut self, title_hidden: bool) -> WindowBuilder {
self.platform_specific.title_hidden = title_hidden; self.platform_specific.title_hidden = title_hidden;
self self
} }
/// Makes the window content appear behind the titlebar
#[inline] #[inline]
fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> WindowBuilder { fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> WindowBuilder {
self.platform_specific.fullsize_content_view = fullsize_content_view; self.platform_specific.fullsize_content_view = fullsize_content_view;
self 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. /// Additional methods on `MonitorId` that are specific to MacOS.

View file

@ -199,9 +199,9 @@ pub trait WindowBuilderExt {
fn with_x11_screen(self, screen_id: i32) -> WindowBuilder; fn with_x11_screen(self, screen_id: i32) -> WindowBuilder;
/// Build window with resize increment hint. Only implemented on X11. /// Build window with resize increment hint. Only implemented on X11.
fn with_resize_increments(self, width_inc: i32, height_inc: i32) -> WindowBuilder; fn with_resize_increments(self, width_inc: u32, height_inc: u32) -> WindowBuilder;
/// Build window with base size hint. Only implemented on X11. /// Build window with base size hint. Only implemented on X11.
fn with_base_size(self, base_width: i32, base_height: i32) -> WindowBuilder; fn with_base_size(self, base_width: u32, base_height: u32) -> WindowBuilder;
} }
impl WindowBuilderExt for WindowBuilder { impl WindowBuilderExt for WindowBuilder {
@ -220,13 +220,13 @@ impl WindowBuilderExt for WindowBuilder {
} }
#[inline] #[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.platform_specific.resize_increments = Some((width_inc, height_inc));
self self
} }
#[inline] #[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.platform_specific.base_size = Some((base_width, base_height));
self self
} }

View file

@ -42,8 +42,8 @@ const BACKEND_PREFERENCE_ENV_VAR: &str = "WINIT_UNIX_BACKEND";
pub struct PlatformSpecificWindowBuilderAttributes { pub struct PlatformSpecificWindowBuilderAttributes {
pub visual_infos: Option<XVisualInfo>, pub visual_infos: Option<XVisualInfo>,
pub screen_id: Option<i32>, pub screen_id: Option<i32>,
pub resize_increments: Option<(i32, i32)>, pub resize_increments: Option<(u32, u32)>,
pub base_size: Option<(i32, i32)>, pub base_size: Option<(u32, u32)>,
} }
lazy_static!( lazy_static!(

View file

@ -488,6 +488,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub titlebar_hidden: bool, pub titlebar_hidden: bool,
pub titlebar_buttons_hidden: bool, pub titlebar_buttons_hidden: bool,
pub fullsize_content_view: bool, pub fullsize_content_view: bool,
pub resize_increments: Option<(u32, u32)>,
} }
pub struct Window2 { pub struct Window2 {
@ -772,6 +773,13 @@ impl Window2 {
window.setMovableByWindowBackground_(YES); 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);
}
}
window.center(); window.center();
window window
}); });