Perform relative_cursor_position calculation vectorwise in ui_focus_system (#8795)

# Objective

This calculation is performed componentwise but all the values are
vectors so it should be using vector operations.
Works correctly with the `relative_cursor_position` example.
This commit is contained in:
ickshonpe 2023-06-09 13:01:07 +01:00 committed by GitHub
parent dc3de5f9b8
commit a1494e53df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -227,12 +227,8 @@ pub fn ui_focus_system(
// The mouse position relative to the node // The mouse position relative to the node
// (0., 0.) is the top-left corner, (1., 1.) is the bottom-right corner // (0., 0.) is the top-left corner, (1., 1.) is the bottom-right corner
let relative_cursor_position = cursor_position.map(|cursor_position| { let relative_cursor_position = cursor_position
Vec2::new( .map(|cursor_position| (cursor_position - min) / node.node.size());
(cursor_position.x - min.x) / node.node.size().x,
(cursor_position.y - min.y) / node.node.size().y,
)
});
// If the current cursor position is within the bounds of the node, consider it for // If the current cursor position is within the bounds of the node, consider it for
// clicking // clicking