bevy/crates
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
..
bevy_a11y Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_animation Some animation doc improvements (#15860) 2024-10-11 20:52:58 +00:00
bevy_app Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
bevy_asset Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_audio Fix audio not playing (#15638) 2024-10-04 01:07:09 +00:00
bevy_color Remove thiserror from bevy_color (#15777) 2024-10-09 14:18:41 +00:00
bevy_core Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_core_pipeline Implement WorldQuery for MainWorld and RenderWorld components (#15745) 2024-10-13 20:58:46 +00:00
bevy_derive move ANDROID_APP to bevy_window (#15585) 2024-10-02 03:01:06 +00:00
bevy_dev_tools split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
bevy_diagnostic Update sysinfo requirement from 0.31.0 to 0.32.0 (#15697) 2024-10-07 07:31:17 +00:00
bevy_dylib Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_ecs Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_encase_derive Update `glam to 0.29, encase` to 0.10. (#15249) 2024-09-23 19:44:02 +00:00
bevy_gilrs Remove thiserror from bevy_gilrs (#15773) 2024-10-09 14:21:25 +00:00
bevy_gizmos Fix gizmos (#15836) 2024-10-10 22:04:04 +00:00
bevy_gltf Remove incorrect equality comparisons for asset load error types (#15890) 2024-10-14 01:00:45 +00:00
bevy_hierarchy Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
bevy_image Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_input Remove thiserror from bevy_input (#15770) 2024-10-09 14:23:01 +00:00
bevy_internal Add mesh picking backend and MeshRayCast system parameter (#15800) 2024-10-13 17:24:19 +00:00
bevy_log Use oslog for ios (#13364) 2024-10-11 08:58:14 +00:00
bevy_macro_utils Modify derive_label to support no_std environments (#15465) 2024-09-27 20:23:26 +00:00
bevy_math Improve PhantomData held by curve adaptors (#15881) 2024-10-13 17:06:21 +00:00
bevy_mesh Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_mikktspace Add no_std support to bevy_mikktspace (#15528) 2024-09-30 18:17:03 +00:00
bevy_pbr Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_picking Add mesh picking backend and MeshRayCast system parameter (#15800) 2024-10-13 17:24:19 +00:00
bevy_ptr Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_reflect Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_remote Remove a dbg! statement left over from debugging (#15867) 2024-10-12 09:07:01 +00:00
bevy_render Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_scene Rename App/World::observe to add_observer, EntityWorldMut::observe_entity to observe. (#15754) 2024-10-09 15:39:29 +00:00
bevy_sprite Implement WorldQuery for MainWorld and RenderWorld components (#15745) 2024-10-13 20:58:46 +00:00
bevy_state Add World::get_resource_or_init as an alternative to World::get_resource_or_insert_with (#15758) 2024-10-09 20:56:26 +00:00
bevy_tasks bump async-channel to 2.3.0 (#15497) 2024-09-28 19:21:59 +00:00
bevy_text split up TextStyle (#15857) 2024-10-13 17:06:22 +00:00
bevy_time Time<Real> documentation improvement (#15874) 2024-10-13 17:26:40 +00:00
bevy_transform Remove thiserror from bevy_transform (#15761) 2024-10-09 14:27:30 +00:00
bevy_ui Clip to the UI node's content box (#15442) 2024-10-15 02:05:08 +00:00
bevy_utils Minor fixes for bevy_utils in no_std (#15463) 2024-10-04 19:25:49 +00:00
bevy_window Add bevy_window::Window options for MacOS (#15820) 2024-10-11 21:11:21 +00:00
bevy_winit force last update after setting state to Suspended (#15888) 2024-10-14 01:40:03 +00:00