Skip to content

Commit

Permalink
Rename resize_increments to surface_resize_increments
Browse files Browse the repository at this point in the history
To make it clear which size the increments apply to.
  • Loading branch information
madsmtm committed Aug 24, 2024
1 parent 528f939 commit faa2d95
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 71 deletions.
4 changes: 2 additions & 2 deletions examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,11 @@ impl CoreWindow for Window {

fn set_max_surface_size(&self, _: Option<Size>) {}

fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None
}

fn set_resize_increments(&self, _increments: Option<Size>) {}
fn set_surface_resize_increments(&self, _increments: Option<Size>) {}

fn set_title(&self, _title: &str) {}

Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/apple/appkit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.resize_increments())
fn surface_resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments())
}

fn set_resize_increments(&self, increments: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments));
fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments));
}

fn set_title(&self, title: &str) {
Expand Down
30 changes: 16 additions & 14 deletions src/platform_impl/apple/appkit/window_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) struct State {
previous_scale_factor: Cell<f64>,

/// The current resize increments for the window content.
resize_increments: Cell<NSSize>,
surface_resize_increments: Cell<NSSize>,
/// Whether the window is showing decorations.
decorations: Cell<bool>,
resizable: Cell<bool>,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 _;

Expand All @@ -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),
Expand Down Expand Up @@ -1002,8 +1004,8 @@ impl WindowDelegate {
self.window().setContentSize(current_size);
}

pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
let increments = self.ivars().resize_increments.get();
pub fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
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()))
Expand All @@ -1012,9 +1014,9 @@ impl WindowDelegate {
}
}

pub fn set_resize_increments(&self, increments: Option<Size>) {
pub fn set_surface_resize_increments(&self, increments: Option<Size>) {
// 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::<f64>(self.scale_factor());
Expand Down
14 changes: 7 additions & 7 deletions src/platform_impl/apple/uikit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ impl Inner {
warn!("`Window::set_max_surface_size` is ignored on iOS")
}

pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
pub fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None
}

#[inline]
pub fn set_resize_increments(&self, _increments: Option<Size>) {
warn!("`Window::set_resize_increments` is ignored on iOS")
pub fn set_surface_resize_increments(&self, _increments: Option<Size>) {
warn!("`Window::set_surface_resize_increments` is ignored on iOS")
}

pub fn set_resizable(&self, _resizable: bool) {
Expand Down Expand Up @@ -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<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.resize_increments())
fn surface_resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments())
}

fn set_resize_increments(&self, increments: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments));
fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments));
}

fn set_title(&self, title: &str) {
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,12 @@ impl CoreWindow for Window {
self.request_redraw();
}

fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None
}

fn set_resize_increments(&self, _increments: Option<Size>) {
warn!("`set_resize_increments` is not implemented for Wayland");
fn set_surface_resize_increments(&self, _increments: Option<Size>) {
warn!("`set_surface_resize_increments` is not implemented for Wayland");
}

fn set_title(&self, title: &str) {
Expand Down
27 changes: 14 additions & 13 deletions src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ impl CoreWindow for Window {
self.0.set_max_surface_size(max_size)
}

fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
self.0.resize_increments()
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
self.0.surface_resize_increments()
}

fn set_resize_increments(&self, increments: Option<Size>) {
self.0.set_resize_increments(increments)
fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.0.set_surface_resize_increments(increments)
}

fn set_title(&self, title: &str) {
Expand Down Expand Up @@ -358,7 +358,7 @@ pub struct SharedState {
pub frame_extents: Option<util::FrameExtentsHeuristic>,
pub min_surface_size: Option<Size>,
pub max_surface_size: Option<Size>,
pub resize_increments: Option<Size>,
pub surface_resize_increments: Option<Size>,
pub base_size: Option<Size>,
pub visibility: Visibility,
pub has_focus: bool,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -1671,7 +1671,7 @@ impl UnownedWindow {
}

#[inline]
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
pub fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
WmSizeHints::get(
self.xconn.xcb_connection(),
self.xwindow as xproto::Window,
Expand All @@ -1685,8 +1685,8 @@ impl UnownedWindow {
}

#[inline]
pub fn set_resize_increments(&self, increments: Option<Size>) {
self.shared_state_lock().resize_increments = increments;
pub fn set_surface_resize_increments(&self, increments: Option<Size>) {
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)
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/orbital/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ impl CoreWindow for Window {
}

#[inline]
fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None
}

#[inline]
fn set_resize_increments(&self, _increments: Option<Size>) {}
fn set_surface_resize_increments(&self, _increments: Option<Size>) {}

#[inline]
fn set_resizable(&self, resizeable: bool) {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ impl RootWindow for Window {
})
}

fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None
}

fn set_resize_increments(&self, _: Option<Size>) {
fn set_surface_resize_increments(&self, _: Option<Size>) {
// Intentionally a no-op: users can't resize canvas elements
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,14 @@ impl CoreWindow for Window {
let _ = self.request_surface_size(size.into());
}

fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
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<Size>) {
self.window_state_lock().resize_increments = increments;
fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.window_state_lock().surface_resize_increments = increments;
}

fn set_resizable(&self, resizable: bool) {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) struct WindowState {
pub min_size: Option<Size>,
pub max_size: Option<Size>,

pub resize_increments: Option<Size>,
pub surface_resize_increments: Option<Size>,

pub window_icon: Option<Icon>,
pub taskbar_icon: Option<Icon>,
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit faa2d95

Please sign in to comment.