mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
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.
This commit is contained in:
parent
5c6628fe3c
commit
3b97fd625a
1 changed files with 10 additions and 3 deletions
|
@ -251,9 +251,16 @@ pub fn ui_focus_system(
|
|||
// The mouse position relative to the node
|
||||
// (0., 0.) is the top-left corner, (1., 1.) is the bottom-right corner
|
||||
// Coordinates are relative to the entire node, not just the visible region.
|
||||
let relative_cursor_position = camera_cursor_positions
|
||||
let relative_cursor_position =
|
||||
camera_cursor_positions
|
||||
.get(&camera_entity)
|
||||
.map(|cursor_position| (*cursor_position - node_rect.min) / node_rect.size());
|
||||
.and_then(|cursor_position| {
|
||||
// ensure node size is non-zero in all dimensions, otherwise relative position will be
|
||||
// +/-inf. if the node is hidden, the visible rect min/max will also be -inf leading to
|
||||
// false positives for mouse_over (#12395)
|
||||
(node_rect.size().cmpgt(Vec2::ZERO).all())
|
||||
.then_some((*cursor_position - node_rect.min) / node_rect.size())
|
||||
});
|
||||
|
||||
// If the current cursor position is within the bounds of the node's visible area, consider it for
|
||||
// clicking
|
||||
|
|
Loading…
Reference in a new issue