Skip to content

Commit bc4d8bb

Browse files
authored
don't attempt to set cursor relative position for zero sized nodes (#12395)
# Objective fix #12007 ## Solution when node size is zero on either axis, set `RelativeCursorPosition::normalized` to None.
1 parent cca4ab3 commit bc4d8bb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/bevy_ui/src/focus.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,16 @@ pub fn ui_focus_system(
252252
// The mouse position relative to the node
253253
// (0., 0.) is the top-left corner, (1., 1.) is the bottom-right corner
254254
// Coordinates are relative to the entire node, not just the visible region.
255-
let relative_cursor_position = camera_cursor_positions
256-
.get(&camera_entity)
257-
.map(|cursor_position| (*cursor_position - node_rect.min) / node_rect.size());
255+
let relative_cursor_position =
256+
camera_cursor_positions
257+
.get(&camera_entity)
258+
.and_then(|cursor_position| {
259+
// ensure node size is non-zero in all dimensions, otherwise relative position will be
260+
// +/-inf. if the node is hidden, the visible rect min/max will also be -inf leading to
261+
// false positives for mouse_over (#12395)
262+
(node_rect.size().cmpgt(Vec2::ZERO).all())
263+
.then_some((*cursor_position - node_rect.min) / node_rect.size())
264+
});
258265

259266
// If the current cursor position is within the bounds of the node's visible area, consider it for
260267
// clicking

0 commit comments

Comments
 (0)