bevy/crates/bevy_ui/src
ickshonpe 100767560f Make clipped areas of UI nodes non-interactive (#10454)
# 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`.
2023-11-29 16:53:01 -08:00
..
layout Update UI alignment docs (#10303) 2023-10-29 15:32:11 +00:00
render Fix panic when using image in UiMaterial (#10591) 2023-11-29 16:46:44 -08:00
widget Fix crash with certain right-aligned text (#10271) 2023-10-26 22:09:34 +00:00
accessibility.rs Various accessibility API updates. (#9989) 2023-10-02 21:22:52 +00:00
camera_config.rs bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
focus.rs Make clipped areas of UI nodes non-interactive (#10454) 2023-11-29 16:53:01 -08:00
geometry.rs don't Implement Display for Val (#10345) 2023-11-02 21:54:41 +00:00
lib.rs Add UI Materials (#9506) 2023-11-03 22:33:01 +00:00
measurement.rs Change the default for the measure_func field of ContentSize to None. (#9346) 2023-08-07 23:06:40 +00:00
node_bundles.rs UI Materials: ignore entities with a BackgroundColor component (#10434) 2023-11-29 16:40:05 -08:00
stack.rs Add stack index to Node (#9853) 2023-10-31 23:32:51 +00:00
ui_material.rs Add UI Materials (#9506) 2023-11-03 22:33:01 +00:00
ui_node.rs Add stack index to Node (#9853) 2023-10-31 23:32:51 +00:00
update.rs Do not panic on non-UI child of UI entity (#9621) 2023-08-29 10:49:40 +00:00