-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make clipped areas of UI nodes non-interactive #10454
Make clipped areas of UI nodes non-interactive #10454
Conversation
* The clipped, non-visible regions of UI nodes are interactive. * `RelativeCursorPostion` is set relative to the visible part of the node. It should be relative to the whole node. Changes: * `ui_focus_system` intersects a node's bounding rect with its clipping rect before checking if mouse over. * `RelativeCursorPostion` is calculated relative to the whole node's position and size, not only the visible part. * Added some outlines to the `overflow` example that respond to `Interaction` changes.
To understand why the relative coordinates change is needed, consider a node that displays a small clipped section of a large map image. Coordinates relative to the visible area would not be sufficient to determine where on the map the cursor is pointing. |
…n node_rect with unwrap_or, instead of binding the intermediate clip_rect variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beside documentation nitpicks, this PR looks good to me (with my limited knowledge of Bevy's internal UI code), and I tested that it fixes one of the bugs in #10668
Could this be modified to still have a Deref
and DerefMut
implementation, though? This would make this PR a candidate to a 0.12 patch release.
I don't think it's correct to implement It is quite a bad bug though, maybe we could merge this and have a separate PR that reimplements |
I was thinking the other way around (implementing Deref and DerefMut here and not implement it in another PR) but the idea is the same: yes I agree it is not "right", but also I think this bug should be fixed in 0.12.x so having a temporary Deref implementation is a small price to pay. |
Let's go with ickshonpe's approach :) |
# Objective Problems: * The clipped, non-visible regions of UI nodes are interactive. * `RelativeCursorPostion` is set relative to the visible part of the node. It should be relative to the whole node. * The `RelativeCursorPostion::mouse_over` method returns `true` when the mouse is over a clipped part of a node. fixes #10470 ## Solution Intersect a node's bounding rect with its clipping rect before checking if it contains the cursor. Added the field `normalized_visible_node_rect` to `RelativeCursorPosition`. This is set to the bounds of the unclipped area of the node rect by `ui_focus_system` expressed in normalized coordinates relative to the entire node. Instead of checking if the normalized cursor position lies within a unit square, it instead checks if it is contained by `normalized_visible_node_rect`. Added outlines to the `overflow` example that appear when the cursor is over the visible part of the images, but not the clipped area. --- ## Changelog * `ui_focus_system` intersects a node's bounding rect with its clipping rect before checking if mouse over. * Added the field `normalized_visible_node_rect` to `RelativeCursorPosition`. This is set to the bounds of the unclipped area of the node rect by `ui_focus_system` expressed in normalized coordinates relative to the entire node. * `RelativeCursorPostion` is calculated relative to the whole node's position and size, not only the visible part. * `RelativeCursorPosition::mouse_over` only returns true when the mouse is over an unclipped region of the UI node. * Removed the `Deref` and `DerefMut` derives from `RelativeCursorPosition` as it is no longer a single field struct. * Added some outlines to the `overflow` example that respond to `Interaction` changes. ## Migration Guide The clipped areas of UI nodes are no longer interactive. `RelativeCursorPostion` is now calculated relative to the whole node's position and size, not only the visible part. Its `mouse_over` method only returns true when the cursor is over an unclipped part of the node. `RelativeCursorPosition` no longer implements `Deref` and `DerefMut`.
# Objective Problems: * The clipped, non-visible regions of UI nodes are interactive. * `RelativeCursorPostion` is set relative to the visible part of the node. It should be relative to the whole node. * The `RelativeCursorPostion::mouse_over` method returns `true` when the mouse is over a clipped part of a node. fixes bevyengine#10470 ## Solution Intersect a node's bounding rect with its clipping rect before checking if it contains the cursor. Added the field `normalized_visible_node_rect` to `RelativeCursorPosition`. This is set to the bounds of the unclipped area of the node rect by `ui_focus_system` expressed in normalized coordinates relative to the entire node. Instead of checking if the normalized cursor position lies within a unit square, it instead checks if it is contained by `normalized_visible_node_rect`. Added outlines to the `overflow` example that appear when the cursor is over the visible part of the images, but not the clipped area. --- ## Changelog * `ui_focus_system` intersects a node's bounding rect with its clipping rect before checking if mouse over. * Added the field `normalized_visible_node_rect` to `RelativeCursorPosition`. This is set to the bounds of the unclipped area of the node rect by `ui_focus_system` expressed in normalized coordinates relative to the entire node. * `RelativeCursorPostion` is calculated relative to the whole node's position and size, not only the visible part. * `RelativeCursorPosition::mouse_over` only returns true when the mouse is over an unclipped region of the UI node. * Removed the `Deref` and `DerefMut` derives from `RelativeCursorPosition` as it is no longer a single field struct. * Added some outlines to the `overflow` example that respond to `Interaction` changes. ## Migration Guide The clipped areas of UI nodes are no longer interactive. `RelativeCursorPostion` is now calculated relative to the whole node's position and size, not only the visible part. Its `mouse_over` method only returns true when the cursor is over an unclipped part of the node. `RelativeCursorPosition` no longer implements `Deref` and `DerefMut`.
Objective
Problems:
RelativeCursorPostion
is set relative to the visible part of the node. It should be relative to the whole node.RelativeCursorPostion::mouse_over
method returnstrue
when the mouse is over a clipped part of a node.fixes #10470
Solution
Intersect a node's bounding rect with its clipping rect before checking if it contains the cursor.
Added the field
normalized_visible_node_rect
toRelativeCursorPosition
. This is set to the bounds of the unclipped area of the node rect byui_focus_system
expressed in normalized coordinates relative to the entire node.Instead of checking if the normalized cursor position lies within a unit square, it instead checks if it is contained by
normalized_visible_node_rect
.Added outlines to the
overflow
example that appear when the cursor is over the visible part of the images, but not the clipped area.Changelog
ui_focus_system
intersects a node's bounding rect with its clipping rect before checking if mouse over.normalized_visible_node_rect
toRelativeCursorPosition
. This is set to the bounds of the unclipped area of the node rect byui_focus_system
expressed in normalized coordinates relative to the entire node.RelativeCursorPostion
is calculated relative to the whole node's position and size, not only the visible part.RelativeCursorPosition::mouse_over
only returns true when the mouse is over an unclipped region of the UI node.Deref
andDerefMut
derives fromRelativeCursorPosition
as it is no longer a single field struct.overflow
example that respond toInteraction
changes.Migration Guide
The clipped areas of UI nodes are no longer interactive.
RelativeCursorPostion
is now calculated relative to the whole node's position and size, not only the visible part. Itsmouse_over
method only returns true when the cursor is over an unclipped part of the node.RelativeCursorPosition
no longer implementsDeref
andDerefMut
.