bevy/examples/ui
ickshonpe b78a060af2
Clip to the UI node's content box (#15442)
# Objective

Change UI clipping to respect borders and padding.

Fixes #15335

## Solution

Based on #15163

1. Add a `padding` field to `Node`.
2. In `ui_layout_size` copy the padding values from taffy to
`Node::padding`.
4. Determine the node's content box (The innermost part of the node
excluding the padding and border).
5. In `update_clipping` perform the clipping intersection with the
node's content box.

## Notes

* `Rect` probably needs some helper methods for working with insets but
because `Rect` and `BorderRect` are in different crates it's awkward to
add them. Left for a follow up.
* We could have another `Overflow` variant (probably called
`Overflow::Hidden`) to that clips inside of the border box instead of
the content box. Left it out here as I'm not certain about the naming or
behaviour though. If this PR is adopted, it would be trivial to add a
`Hidden` variant in a follow up.
* Depending on UI scaling there are sometimes gaps in the layout:
<img width="532" alt="rounding-bug"
src="https://github.com/user-attachments/assets/cc29aa0d-44fe-403f-8f0e-cd28a8b1d1b3">
This is caused by existing bugs in `ui_layout_system`'s coordinates
rounding and not anything to do with the changes in this PR.

## Testing

This PR also changes the `overflow` example to display borders on the
overflow nodes so you can see how this works:

#### main (The image is clipped at the edges of the node, overwriting
the border).
<img width="722" alt="main_overflow"
src="https://github.com/user-attachments/assets/eb316cd0-fff8-46ee-b481-e0cd6bab3f5c">

#### this PR  (The image is clipped at the edges of the node's border).
<img width="711" alt="content-box-clip"
src="https://github.com/user-attachments/assets/fb302e56-9302-47b9-9a29-ec3e15fe9a9f">

## Migration Guide

Migration guide is on #15561

---------

Co-authored-by: UkoeHB <37489173+UkoeHB@users.noreply.github.com>
2024-10-15 02:05:08 +00:00
..
borders.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
box_shadow.rs box shadow (#15204) 2024-10-08 16:26:17 +00:00
button.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
display_and_visibility.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
flex_layout.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
font_atlas_debug.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
ghost_nodes.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
grid.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
overflow.rs Clip to the UI node's content box (#15442) 2024-10-15 02:05:08 +00:00
overflow_debug.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
relative_cursor_position.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
render_ui_to_texture.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
scroll.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
size_constraints.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
text.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
text_debug.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
text_wrap_debug.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
transparency_ui.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
ui.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
ui_material.rs Replace Handle<M: UiMaterial> component with UiMaterialHandle wrapper (#15740) 2024-10-08 19:07:58 +00:00
ui_scaling.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
ui_texture_atlas.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
ui_texture_atlas_slice.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
ui_texture_slice.rs split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
ui_texture_slice_flip_and_tile.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
viewport_debug.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
window_fallthrough.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
z_index.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00