diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index aef34b31e9..cd9c66727a 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -525,7 +525,7 @@ pub fn extract_uinode_borders( let border_radius = clamp_radius(border_radius, uinode.size(), border.into()); // don't extract border if no border or the node is zero-sized (a zero sized node can still have an outline). - if uinode.size().x > 0. && uinode.size().y > 0. && border != [0.; 4] { + if !uinode.is_empty() && border != [0.; 4] { if let Some(border_color) = maybe_border_color { extracted_uinodes.uinodes.insert( commands.spawn_empty().id(), @@ -698,7 +698,7 @@ pub fn extract_uinode_text( }; // Skip if not visible or if size is set to zero (e.g. when a parent is set to `Display::None`) - if !view_visibility.get() || uinode.size().x == 0. || uinode.size().y == 0. { + if !view_visibility.get() || uinode.is_empty() { continue; } diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 1038af79fd..eb6e6fed99 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -63,6 +63,13 @@ impl Node { self.calculated_size } + /// Check if the node is empty. + /// A node is considered empty if it has a zero or negative extent along either of its axes. + #[inline] + pub fn is_empty(&self) -> bool { + self.size().cmple(Vec2::ZERO).any() + } + /// The order of the node in the UI layout. /// Nodes with a higher stack index are drawn on top of and receive interactions before nodes with lower stack indices. pub const fn stack_index(&self) -> u32 {