diff --git a/examples/window.rs b/examples/window.rs index 7243a2f827..9ea98f3bb0 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -681,12 +681,12 @@ impl WindowState { /// Toggle resize increments on a window. fn toggle_resize_increments(&mut self) { - let new_increments = match self.window.resize_increments() { + let new_increments = match self.window.surface_resize_increments() { Some(_) => None, None => Some(LogicalSize::new(25.0, 25.0).into()), }; info!("Had increments: {}", new_increments.is_none()); - self.window.set_resize_increments(new_increments); + self.window.set_surface_resize_increments(new_increments); } /// Toggle fullscreen. diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 1dc2178ced..1da2a0130d 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -824,11 +824,11 @@ impl CoreWindow for Window { fn set_max_surface_size(&self, _: Option) {} - fn resize_increments(&self) -> Option> { + fn surface_resize_increments(&self) -> Option> { None } - fn set_resize_increments(&self, _increments: Option) {} + fn set_surface_resize_increments(&self, _increments: Option) {} fn set_title(&self, _title: &str) {} diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 4deaf362cb..11c241dc45 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -147,12 +147,12 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size)); } - fn resize_increments(&self) -> Option> { - self.maybe_wait_on_main(|delegate| delegate.resize_increments()) + fn surface_resize_increments(&self) -> Option> { + self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments()) } - fn set_resize_increments(&self, increments: Option) { - self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments)); + fn set_surface_resize_increments(&self, increments: Option) { + self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments)); } fn set_title(&self, title: &str) { diff --git a/src/platform_impl/apple/appkit/window_delegate.rs b/src/platform_impl/apple/appkit/window_delegate.rs index a79ce4b622..43f907e599 100644 --- a/src/platform_impl/apple/appkit/window_delegate.rs +++ b/src/platform_impl/apple/appkit/window_delegate.rs @@ -93,7 +93,7 @@ pub(crate) struct State { previous_scale_factor: Cell, /// The current resize increments for the window content. - resize_increments: Cell, + surface_resize_increments: Cell, /// Whether the window is showing decorations. decorations: Cell, resizable: Cell, @@ -169,7 +169,7 @@ declare_class!( fn window_will_start_live_resize(&self, _: Option<&AnyObject>) { trace_scope!("windowWillStartLiveResize:"); - let increments = self.ivars().resize_increments.get(); + let increments = self.ivars().surface_resize_increments.get(); self.set_resize_increments_inner(increments); } @@ -700,13 +700,15 @@ impl WindowDelegate { None => (), } - let resize_increments = - match attrs.resize_increments.map(|i| i.to_logical(window.backingScaleFactor() as _)) { - Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => { - NSSize::new(width, height) - }, - _ => NSSize::new(1., 1.), - }; + let surface_resize_increments = match attrs + .surface_resize_increments + .map(|i| i.to_logical(window.backingScaleFactor() as _)) + { + Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => { + NSSize::new(width, height) + }, + _ => NSSize::new(1., 1.), + }; let scale_factor = window.backingScaleFactor() as _; @@ -719,7 +721,7 @@ impl WindowDelegate { window: window.retain(), previous_position: Cell::new(None), previous_scale_factor: Cell::new(scale_factor), - resize_increments: Cell::new(resize_increments), + surface_resize_increments: Cell::new(surface_resize_increments), decorations: Cell::new(attrs.decorations), resizable: Cell::new(attrs.resizable), maximized: Cell::new(attrs.maximized), @@ -1002,8 +1004,8 @@ impl WindowDelegate { self.window().setContentSize(current_size); } - pub fn resize_increments(&self) -> Option> { - let increments = self.ivars().resize_increments.get(); + pub fn surface_resize_increments(&self) -> Option> { + let increments = self.ivars().surface_resize_increments.get(); let (w, h) = (increments.width, increments.height); if w > 1.0 || h > 1.0 { Some(LogicalSize::new(w, h).to_physical(self.scale_factor())) @@ -1012,9 +1014,9 @@ impl WindowDelegate { } } - pub fn set_resize_increments(&self, increments: Option) { + pub fn set_surface_resize_increments(&self, increments: Option) { // XXX the resize increments are only used during live resizes. - self.ivars().resize_increments.set( + self.ivars().surface_resize_increments.set( increments .map(|increments| { let logical = increments.to_logical::(self.scale_factor()); diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index 90a0ec9f8c..6e01947813 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -219,13 +219,13 @@ impl Inner { warn!("`Window::set_max_surface_size` is ignored on iOS") } - pub fn resize_increments(&self) -> Option> { + pub fn surface_resize_increments(&self) -> Option> { None } #[inline] - pub fn set_resize_increments(&self, _increments: Option) { - warn!("`Window::set_resize_increments` is ignored on iOS") + pub fn set_surface_resize_increments(&self, _increments: Option) { + warn!("`Window::set_surface_resize_increments` is ignored on iOS") } pub fn set_resizable(&self, _resizable: bool) { @@ -642,12 +642,12 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size)); } - fn resize_increments(&self) -> Option> { - self.maybe_wait_on_main(|delegate| delegate.resize_increments()) + fn surface_resize_increments(&self) -> Option> { + self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments()) } - fn set_resize_increments(&self, increments: Option) { - self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments)); + fn set_surface_resize_increments(&self, increments: Option) { + self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments)); } fn set_title(&self, title: &str) { diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index b07fe0f683..2bee894a30 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -358,12 +358,12 @@ impl CoreWindow for Window { self.request_redraw(); } - fn resize_increments(&self) -> Option> { + fn surface_resize_increments(&self) -> Option> { None } - fn set_resize_increments(&self, _increments: Option) { - warn!("`set_resize_increments` is not implemented for Wayland"); + fn set_surface_resize_increments(&self, _increments: Option) { + warn!("`set_surface_resize_increments` is not implemented for Wayland"); } fn set_title(&self, title: &str) { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index fe80e928d5..c56e5f7080 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -114,12 +114,12 @@ impl CoreWindow for Window { self.0.set_max_surface_size(max_size) } - fn resize_increments(&self) -> Option> { - self.0.resize_increments() + fn surface_resize_increments(&self) -> Option> { + self.0.surface_resize_increments() } - fn set_resize_increments(&self, increments: Option) { - self.0.set_resize_increments(increments) + fn set_surface_resize_increments(&self, increments: Option) { + self.0.set_surface_resize_increments(increments) } fn set_title(&self, title: &str) { @@ -358,7 +358,7 @@ pub struct SharedState { pub frame_extents: Option, pub min_surface_size: Option, pub max_surface_size: Option, - pub resize_increments: Option, + pub surface_resize_increments: Option, pub base_size: Option, pub visibility: Visibility, pub has_focus: bool, @@ -398,7 +398,7 @@ impl SharedState { frame_extents: None, min_surface_size: None, max_surface_size: None, - resize_increments: None, + surface_resize_increments: None, base_size: None, has_focus: false, cursor_hittest: None, @@ -734,7 +734,7 @@ impl UnownedWindow { let shared_state = window.shared_state.get_mut().unwrap(); shared_state.min_surface_size = min_surface_size.map(Into::into); shared_state.max_surface_size = max_surface_size.map(Into::into); - shared_state.resize_increments = window_attrs.resize_increments; + shared_state.surface_resize_increments = window_attrs.surface_resize_increments; shared_state.base_size = window_attrs.platform_specific.x11.base_size; let normal_hints = WmSizeHints { @@ -749,7 +749,7 @@ impl UnownedWindow { max_size: max_surface_size.map(cast_physical_size_to_hint), min_size: min_surface_size.map(cast_physical_size_to_hint), size_increment: window_attrs - .resize_increments + .surface_resize_increments .map(|size| cast_size_to_hint(size, scale_factor)), base_size: window_attrs .platform_specific @@ -1671,7 +1671,7 @@ impl UnownedWindow { } #[inline] - pub fn resize_increments(&self) -> Option> { + pub fn surface_resize_increments(&self) -> Option> { WmSizeHints::get( self.xconn.xcb_connection(), self.xwindow as xproto::Window, @@ -1685,8 +1685,8 @@ impl UnownedWindow { } #[inline] - pub fn set_resize_increments(&self, increments: Option) { - self.shared_state_lock().resize_increments = increments; + pub fn set_surface_resize_increments(&self, increments: Option) { + self.shared_state_lock().surface_resize_increments = increments; let physical_increments = increments.map(|increments| cast_size_to_hint(increments, self.scale_factor())); self.update_normal_hints(|hints| hints.size_increment = physical_increments) @@ -1706,12 +1706,13 @@ impl UnownedWindow { let dpi_adjuster = |size: Size| -> (i32, i32) { cast_size_to_hint(size, scale_factor) }; let max_size = shared_state.max_surface_size.map(dpi_adjuster); let min_size = shared_state.min_surface_size.map(dpi_adjuster); - let resize_increments = shared_state.resize_increments.map(dpi_adjuster); + let surface_resize_increments = + shared_state.surface_resize_increments.map(dpi_adjuster); let base_size = shared_state.base_size.map(dpi_adjuster); normal_hints.max_size = max_size; normal_hints.min_size = min_size; - normal_hints.size_increment = resize_increments; + normal_hints.size_increment = surface_resize_increments; normal_hints.base_size = base_size; }) .expect("Failed to update normal hints"); diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index dd36d725bb..c23cd88efa 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -283,12 +283,12 @@ impl CoreWindow for Window { } #[inline] - fn resize_increments(&self) -> Option> { + fn surface_resize_increments(&self) -> Option> { None } #[inline] - fn set_resize_increments(&self, _increments: Option) {} + fn set_surface_resize_increments(&self, _increments: Option) {} #[inline] fn set_resizable(&self, resizeable: bool) { diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 9086cac967..239c58e9d5 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -173,11 +173,11 @@ impl RootWindow for Window { }) } - fn resize_increments(&self) -> Option> { + fn surface_resize_increments(&self) -> Option> { None } - fn set_resize_increments(&self, _: Option) { + fn set_surface_resize_increments(&self, _: Option) { // Intentionally a no-op: users can't resize canvas elements } diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 6a92f427ec..b71a8f1c73 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1308,7 +1308,7 @@ unsafe fn public_window_callback_inner( let scale_factor = userdata.window_state_lock().scale_factor; let Some(inc) = userdata .window_state_lock() - .resize_increments + .surface_resize_increments .map(|inc| inc.to_physical(scale_factor)) .filter(|inc| inc.width > 0 && inc.height > 0) else { diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 9d91149097..c08cc436ae 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -513,14 +513,14 @@ impl CoreWindow for Window { let _ = self.request_surface_size(size.into()); } - fn resize_increments(&self) -> Option> { + fn surface_resize_increments(&self) -> Option> { let w = self.window_state_lock(); let scale_factor = w.scale_factor; - w.resize_increments.map(|size| size.to_physical(scale_factor)) + w.surface_resize_increments.map(|size| size.to_physical(scale_factor)) } - fn set_resize_increments(&self, increments: Option) { - self.window_state_lock().resize_increments = increments; + fn set_surface_resize_increments(&self, increments: Option) { + self.window_state_lock().surface_resize_increments = increments; } fn set_resizable(&self, resizable: bool) { diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index c81bbd090d..f84dd2cfdb 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -30,7 +30,7 @@ pub(crate) struct WindowState { pub min_size: Option, pub max_size: Option, - pub resize_increments: Option, + pub surface_resize_increments: Option, pub window_icon: Option, pub taskbar_icon: Option, @@ -154,7 +154,7 @@ impl WindowState { min_size: attributes.min_surface_size, max_size: attributes.max_surface_size, - resize_increments: attributes.resize_increments, + surface_resize_increments: attributes.surface_resize_increments, window_icon: attributes.window_icon.clone(), taskbar_icon: None, diff --git a/src/window.rs b/src/window.rs index 2dbccb1e71..e01284d4b5 100644 --- a/src/window.rs +++ b/src/window.rs @@ -60,6 +60,7 @@ pub struct WindowAttributes { pub surface_size: Option, pub min_surface_size: Option, pub max_surface_size: Option, + pub surface_resize_increments: Option, pub position: Option, pub resizable: bool, pub enabled_buttons: WindowButtons, @@ -71,7 +72,6 @@ pub struct WindowAttributes { pub decorations: bool, pub window_icon: Option, pub preferred_theme: Option, - pub resize_increments: Option, pub content_protected: bool, pub window_level: WindowLevel, pub active: bool, @@ -91,6 +91,7 @@ impl Default for WindowAttributes { surface_size: None, min_surface_size: None, max_surface_size: None, + surface_resize_increments: None, position: None, resizable: true, enabled_buttons: WindowButtons::all(), @@ -104,7 +105,6 @@ impl Default for WindowAttributes { window_level: Default::default(), window_icon: None, preferred_theme: None, - resize_increments: None, content_protected: false, cursor: Cursor::default(), #[cfg(feature = "rwh_06")] @@ -172,6 +172,20 @@ impl WindowAttributes { self } + /// Build window with resize increments hint. + /// + /// The default is `None`. + /// + /// See [`Window::set_surface_resize_increments`] for details. + #[inline] + pub fn with_surface_resize_increments>( + mut self, + surface_resize_increments: S, + ) -> Self { + self.surface_resize_increments = Some(surface_resize_increments.into()); + self + } + /// Sets a desired initial position for the window. /// /// If this is not set, some platform-specific position will be chosen. @@ -346,17 +360,6 @@ impl WindowAttributes { self } - /// Build window with resize increments hint. - /// - /// The default is `None`. - /// - /// See [`Window::set_resize_increments`] for details. - #[inline] - pub fn with_resize_increments>(mut self, resize_increments: S) -> Self { - self.resize_increments = Some(resize_increments.into()); - self - } - /// Prevents the window contents from being captured by other apps. /// /// The default is `false`. @@ -756,7 +759,7 @@ pub trait Window: AsAny + Send + Sync { /// ## Platform-specific /// /// - **iOS / Android / Web / Wayland / Orbital:** Always returns [`None`]. - fn resize_increments(&self) -> Option>; + fn surface_resize_increments(&self) -> Option>; /// Sets window resize increments. /// @@ -769,7 +772,7 @@ pub trait Window: AsAny + Send + Sync { /// numbers. /// - **Wayland:** Not implemented. /// - **iOS / Android / Web / Orbital:** Unsupported. - fn set_resize_increments(&self, increments: Option); + fn set_surface_resize_increments(&self, increments: Option); /// Modifies the title of the window. ///