From 3751faedc4ce728e65461c132a54a1611dfcd91c Mon Sep 17 00:00:00 2001 From: Brandon S <116681127+bsibb22@users.noreply.github.com> Date: Mon, 17 Feb 2025 09:30:54 -0500 Subject: [PATCH 1/5] Added ComputedNode.logical_size() method, returns node size accounting for window scale --- crates/bevy_ui/src/ui_node.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 96d9d2aeb2..2c9e5434c3 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -118,6 +118,13 @@ impl ComputedNode { self.unrounded_size } + /// The calculate node size as width and height in physical pixels, accounting for a non-uniform window scale factor. + /// + #[inline] + pub const fn logical_size(&self) -> Vec2 { + self.size * self.inverse_scale_factor + } + /// Returns the thickness of the UI node's outline in physical pixels. /// If this value is negative or `0.` then no outline will be rendered. /// From fbacac3b9bdcd59eb4354dd7e3453b45cf68adea Mon Sep 17 00:00:00 2001 From: Brandon S <116681127+bsibb22@users.noreply.github.com> Date: Mon, 17 Feb 2025 09:37:56 -0500 Subject: [PATCH 2/5] Fixed typo in comments --- crates/bevy_ui/src/ui_node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 2c9e5434c3..d84d2a1019 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -118,7 +118,7 @@ impl ComputedNode { self.unrounded_size } - /// The calculate node size as width and height in physical pixels, accounting for a non-uniform window scale factor. + /// The calculated node size as width and height in physical pixels, accounting for a non-uniform window scale factor. /// #[inline] pub const fn logical_size(&self) -> Vec2 { From baabdffca123fb97faae63e9f6c21d2216513d5f Mon Sep 17 00:00:00 2001 From: Brandon S <116681127+bsibb22@users.noreply.github.com> Date: Mon, 17 Feb 2025 09:45:23 -0500 Subject: [PATCH 3/5] Removed non-const function calls --- crates/bevy_ui/src/ui_node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index d84d2a1019..a0586e8dc7 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -122,7 +122,7 @@ impl ComputedNode { /// #[inline] pub const fn logical_size(&self) -> Vec2 { - self.size * self.inverse_scale_factor + self.size() * self.inverse_scale_factor() } /// Returns the thickness of the UI node's outline in physical pixels. From 94cc602b61d93bcc7de0f95ae4729944b038c1cf Mon Sep 17 00:00:00 2001 From: Brandon S <116681127+bsibb22@users.noreply.github.com> Date: Mon, 17 Feb 2025 10:07:15 -0500 Subject: [PATCH 4/5] Fixing constness --- crates/bevy_ui/src/ui_node.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index a0586e8dc7..be038e04c0 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -122,7 +122,9 @@ impl ComputedNode { /// #[inline] pub const fn logical_size(&self) -> Vec2 { - self.size() * self.inverse_scale_factor() + let s = self.size(); + let scale_fac = self.inverse_scale_factor(); + s * scale_fac } /// Returns the thickness of the UI node's outline in physical pixels. From 15939a3425c33ea6605cc9f07ee6da91edfda9ff Mon Sep 17 00:00:00 2001 From: Brandon S <116681127+bsibb22@users.noreply.github.com> Date: Mon, 17 Feb 2025 10:11:05 -0500 Subject: [PATCH 5/5] Fixed constness (actually) --- crates/bevy_ui/src/ui_node.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index be038e04c0..9fab8dcc7f 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -121,10 +121,8 @@ impl ComputedNode { /// The calculated node size as width and height in physical pixels, accounting for a non-uniform window scale factor. /// #[inline] - pub const fn logical_size(&self) -> Vec2 { - let s = self.size(); - let scale_fac = self.inverse_scale_factor(); - s * scale_fac + pub fn logical_size(&self) -> Vec2 { + self.size() * self.inverse_scale_factor() } /// Returns the thickness of the UI node's outline in physical pixels.