From 1830d34c6fd1543c4f76b2bed6161cf5be2c8d73 Mon Sep 17 00:00:00 2001 From: kanatapple Date: Thu, 20 Jun 2024 18:34:53 +0900 Subject: [PATCH 1/5] fix: Set physical values --- src/webview2/mod.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index 7f73d1719..8cb066b12 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -9,7 +9,7 @@ use std::{ borrow::Cow, cell::RefCell, collections::HashSet, fmt::Write, path::PathBuf, rc::Rc, sync::mpsc, }; -use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; +use dpi::{PhysicalPosition, PhysicalSize}; use http::{Request, Response as HttpResponse, StatusCode}; use once_cell::sync::Lazy; use raw_window_handle::{HasWindowHandle, RawWindowHandle}; @@ -1178,10 +1178,12 @@ impl InnerWebView { } pub fn bounds(&self) -> Result { - let mut bounds = Rect::default(); + let dpi = unsafe { util::hwnd_dpi(self.hwnd) }; + let scale_factor = util::dpi_to_scale_factor(dpi); + let mut bounds = Rect::default(); + let mut rect = RECT::default(); if self.is_child { - let mut rect = RECT::default(); unsafe { GetClientRect(self.hwnd, &mut rect)? }; let position_point = &mut [POINT { @@ -1190,22 +1192,17 @@ impl InnerWebView { }]; unsafe { MapWindowPoints(self.hwnd, *self.parent.borrow(), position_point) }; - bounds.position = LogicalPosition::new(position_point[0].x, position_point[0].y).into(); - bounds.size = LogicalSize::new( - (rect.right - rect.left) as u32, - (rect.bottom - rect.top) as u32, - ) - .into(); + bounds.position = PhysicalPosition::new(position_point[0].x, position_point[0].y) + .to_logical::(scale_factor) + .into(); } else { - let mut rect = RECT::default(); unsafe { self.controller.Bounds(&mut rect) }?; - bounds.size = LogicalSize::new( - (rect.right - rect.left) as u32, - (rect.bottom - rect.top) as u32, - ) - .into(); } + bounds.size = PhysicalSize::new(rect.right - rect.left, rect.bottom - rect.top) + .to_logical::(scale_factor) + .into(); + Ok(bounds) } From b8d6730e0164211f2aaf660fcd495ea571d99437 Mon Sep 17 00:00:00 2001 From: kanatapple Date: Mon, 24 Jun 2024 13:36:37 +0900 Subject: [PATCH 2/5] Add change file --- .changes/fix-convert-physical-to-logical-in-bounds.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/fix-convert-physical-to-logical-in-bounds.md diff --git a/.changes/fix-convert-physical-to-logical-in-bounds.md b/.changes/fix-convert-physical-to-logical-in-bounds.md new file mode 100644 index 000000000..b44c1a3d1 --- /dev/null +++ b/.changes/fix-convert-physical-to-logical-in-bounds.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Convert physical position/size to logical values in bounds method From 518f4cf9a4ac3bf2a787c25c91fc514c67fa7600 Mon Sep 17 00:00:00 2001 From: kanatapple Date: Mon, 24 Jun 2024 16:29:54 +0900 Subject: [PATCH 3/5] Fix for reviews --- ...bounds.md => fix-set-physical-values-in-bounds.md} | 0 src/webview2/mod.rs | 11 ++--------- 2 files changed, 2 insertions(+), 9 deletions(-) rename .changes/{fix-convert-physical-to-logical-in-bounds.md => fix-set-physical-values-in-bounds.md} (100%) diff --git a/.changes/fix-convert-physical-to-logical-in-bounds.md b/.changes/fix-set-physical-values-in-bounds.md similarity index 100% rename from .changes/fix-convert-physical-to-logical-in-bounds.md rename to .changes/fix-set-physical-values-in-bounds.md diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index 8cb066b12..d32253cec 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -1178,9 +1178,6 @@ impl InnerWebView { } pub fn bounds(&self) -> Result { - let dpi = unsafe { util::hwnd_dpi(self.hwnd) }; - let scale_factor = util::dpi_to_scale_factor(dpi); - let mut bounds = Rect::default(); let mut rect = RECT::default(); if self.is_child { @@ -1192,16 +1189,12 @@ impl InnerWebView { }]; unsafe { MapWindowPoints(self.hwnd, *self.parent.borrow(), position_point) }; - bounds.position = PhysicalPosition::new(position_point[0].x, position_point[0].y) - .to_logical::(scale_factor) - .into(); + bounds.position = PhysicalPosition::new(position_point[0].x, position_point[0].y).into(); } else { unsafe { self.controller.Bounds(&mut rect) }?; } - bounds.size = PhysicalSize::new(rect.right - rect.left, rect.bottom - rect.top) - .to_logical::(scale_factor) - .into(); + bounds.size = PhysicalSize::new(rect.right - rect.left, rect.bottom - rect.top).into(); Ok(bounds) } From 49acdd99e82afc17823d76538492368377d826e5 Mon Sep 17 00:00:00 2001 From: kanatapple Date: Mon, 24 Jun 2024 17:06:16 +0900 Subject: [PATCH 4/5] Fix change file --- .changes/fix-set-physical-values-in-bounds.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/fix-set-physical-values-in-bounds.md b/.changes/fix-set-physical-values-in-bounds.md index b44c1a3d1..099dd8fd9 100644 --- a/.changes/fix-set-physical-values-in-bounds.md +++ b/.changes/fix-set-physical-values-in-bounds.md @@ -2,4 +2,4 @@ "wry": patch --- -Convert physical position/size to logical values in bounds method +Set physical values in bounds method From 566b53b25fe28efa1db4fbeeb0bb2218b0fa6451 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 10 Jul 2024 15:19:23 +0300 Subject: [PATCH 5/5] Update .changes/fix-set-physical-values-in-bounds.md --- .changes/fix-set-physical-values-in-bounds.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/fix-set-physical-values-in-bounds.md b/.changes/fix-set-physical-values-in-bounds.md index 099dd8fd9..2c00b8a1d 100644 --- a/.changes/fix-set-physical-values-in-bounds.md +++ b/.changes/fix-set-physical-values-in-bounds.md @@ -2,4 +2,4 @@ "wry": patch --- -Set physical values in bounds method +Fix `Webview::bounds` returning logical values where it should have been physical.