diff --git a/.changes/window-builder-physical-size.md b/.changes/window-builder-physical-size.md new file mode 100644 index 000000000000..7008e41e726d --- /dev/null +++ b/.changes/window-builder-physical-size.md @@ -0,0 +1,7 @@ +--- +'tauri': 'minor:feat' +'tauri-runtime': 'minor:feat' +'tauri-runtime-wry': 'minor:feat' +--- + +Add physical coordinate methods to WindowBuilder: `position_physical`, `inner_size_physical`, `min_inner_size_physical`, and `max_inner_size_physical` (fix #5228). diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 821fbacec9a9..a4942dbf6008 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -945,6 +945,11 @@ impl WindowBuilder for WindowBuilderWrapper { self } + fn position_physical(mut self, x: i32, y: i32) -> Self { + self.inner = self.inner.with_position(TaoPhysicalPosition::new(x, y)); + self + } + fn inner_size(mut self, width: f64, height: f64) -> Self { self.inner = self .inner @@ -952,6 +957,13 @@ impl WindowBuilder for WindowBuilderWrapper { self } + fn inner_size_physical(mut self, width: u32, height: u32) -> Self { + self.inner = self + .inner + .with_inner_size(TaoPhysicalSize::new(width, height)); + self + } + fn min_inner_size(mut self, min_width: f64, min_height: f64) -> Self { self.inner = self .inner @@ -959,6 +971,13 @@ impl WindowBuilder for WindowBuilderWrapper { self } + fn min_inner_size_physical(mut self, min_width: u32, min_height: u32) -> Self { + self.inner = self + .inner + .with_min_inner_size(TaoPhysicalSize::new(min_width, min_height)); + self + } + fn max_inner_size(mut self, max_width: f64, max_height: f64) -> Self { self.inner = self .inner @@ -966,6 +985,13 @@ impl WindowBuilder for WindowBuilderWrapper { self } + fn max_inner_size_physical(mut self, max_width: u32, max_height: u32) -> Self { + self.inner = self + .inner + .with_max_inner_size(TaoPhysicalSize::new(max_width, max_height)); + self + } + fn inner_size_constraints(mut self, constraints: WindowSizeConstraints) -> Self { self.inner.window.inner_size_constraints = tao::window::WindowSizeConstraints { min_width: constraints.min_width, diff --git a/crates/tauri-runtime/src/window.rs b/crates/tauri-runtime/src/window.rs index 652832c1ec49..86a8cb28d042 100644 --- a/crates/tauri-runtime/src/window.rs +++ b/crates/tauri-runtime/src/window.rs @@ -251,18 +251,34 @@ pub trait WindowBuilder: WindowBuilderBase { #[must_use] fn position(self, x: f64, y: f64) -> Self; + /// The initial position of the window in physical pixels. + #[must_use] + fn position_physical(self, x: i32, y: i32) -> Self; + /// Window size in logical pixels. #[must_use] fn inner_size(self, width: f64, height: f64) -> Self; + /// Window size in physical pixels. + #[must_use] + fn inner_size_physical(self, width: u32, height: u32) -> Self; + /// Window min inner size in logical pixels. #[must_use] fn min_inner_size(self, min_width: f64, min_height: f64) -> Self; + /// Window min inner size in physical pixels. + #[must_use] + fn min_inner_size_physical(self, min_width: u32, min_height: u32) -> Self; + /// Window max inner size in logical pixels. #[must_use] fn max_inner_size(self, max_width: f64, max_height: f64) -> Self; + /// Window max inner size in physical pixels. + #[must_use] + fn max_inner_size_physical(self, max_width: u32, max_height: u32) -> Self; + /// Window inner size constraints. #[must_use] fn inner_size_constraints(self, constraints: WindowSizeConstraints) -> Self; diff --git a/crates/tauri/src/window/mod.rs b/crates/tauri/src/window/mod.rs index a67784cc3351..4679025ab4e6 100644 --- a/crates/tauri/src/window/mod.rs +++ b/crates/tauri/src/window/mod.rs @@ -450,6 +450,13 @@ impl<'a, R: Runtime, M: Manager> WindowBuilder<'a, R, M> { self } + /// The initial position of the window in physical pixels. + #[must_use] + pub fn position_physical(mut self, x: i32, y: i32) -> Self { + self.window_builder = self.window_builder.position_physical(x, y); + self + } + /// Window size in logical pixels. #[must_use] pub fn inner_size(mut self, width: f64, height: f64) -> Self { @@ -457,6 +464,13 @@ impl<'a, R: Runtime, M: Manager> WindowBuilder<'a, R, M> { self } + /// Window size in physical pixels. + #[must_use] + pub fn inner_size_physical(mut self, width: u32, height: u32) -> Self { + self.window_builder = self.window_builder.inner_size_physical(width, height); + self + } + /// Window min inner size in logical pixels. #[must_use] pub fn min_inner_size(mut self, min_width: f64, min_height: f64) -> Self { @@ -464,6 +478,13 @@ impl<'a, R: Runtime, M: Manager> WindowBuilder<'a, R, M> { self } + /// Window min inner size in physical pixels. + #[must_use] + pub fn min_inner_size_physical(mut self, min_width: u32, min_height: u32) -> Self { + self.window_builder = self.window_builder.min_inner_size_physical(min_width, min_height); + self + } + /// Window max inner size in logical pixels. #[must_use] pub fn max_inner_size(mut self, max_width: f64, max_height: f64) -> Self { @@ -471,6 +492,13 @@ impl<'a, R: Runtime, M: Manager> WindowBuilder<'a, R, M> { self } + /// Window max inner size in physical pixels. + #[must_use] + pub fn max_inner_size_physical(mut self, max_width: u32, max_height: u32) -> Self { + self.window_builder = self.window_builder.max_inner_size_physical(max_width, max_height); + self + } + /// Window inner size constraints. #[must_use] pub fn inner_size_constraints(