Skip to content
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

Merged
merged 8 commits into from
Nov 22, 2023

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Nov 8, 2023

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.

* 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.
@ickshonpe ickshonpe added C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change A-Utils Utility functions and types labels Nov 8, 2023
@ickshonpe
Copy link
Contributor Author

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.

crates/bevy_ui/src/focus.rs Outdated Show resolved Hide resolved
@ickshonpe ickshonpe added A-UI Graphical user interfaces, styles, layouts, and widgets and removed A-Utils Utility functions and types labels Nov 9, 2023
@alice-i-cecile alice-i-cecile self-requested a review November 21, 2023 00:28
@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Nov 21, 2023
Copy link
Member

@Selene-Amanita Selene-Amanita left a 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.

crates/bevy_ui/src/focus.rs Show resolved Hide resolved
crates/bevy_ui/src/focus.rs Outdated Show resolved Hide resolved
@ickshonpe
Copy link
Contributor Author

ickshonpe commented Nov 21, 2023

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 Deref and DerefMut now that the type has two fields.

It is quite a bad bug though, maybe we could merge this and have a separate PR that reimplements Deref and DerefMut just for any 0.12 patch releases?

@Selene-Amanita
Copy link
Member

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.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Nov 22, 2023
@alice-i-cecile alice-i-cecile added this to the 0.12.1 milestone Nov 22, 2023
@alice-i-cecile
Copy link
Member

alice-i-cecile commented Nov 22, 2023

Let's go with ickshonpe's approach :)

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Nov 22, 2023
Merged via the queue into bevyengine:main with commit bca057d Nov 22, 2023
45 checks passed
cart pushed a commit that referenced this pull request Nov 30, 2023
# 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`.
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# 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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui_focus_system ignores clipping
4 participants