Skip to content

use precomputed border values#15163

Merged
alice-i-cecile merged 35 commits intobevyengine:mainfrom
ickshonpe:update-borders-in-layout
Sep 26, 2024
Merged

use precomputed border values#15163
alice-i-cecile merged 35 commits intobevyengine:mainfrom
ickshonpe:update-borders-in-layout

Conversation

@ickshonpe
Copy link
Copy Markdown
Contributor

@ickshonpe ickshonpe commented Sep 11, 2024

Objective

Fixes #15142

Solution

  • Moved all the UI border geometry calculations that were scattered through the UI extraction functions into ui_layout_system.
  • Added a border: BorderRect field to Node to store the border size computed by ui_layout_system.
  • Use the border values returned from Taffy rather than calculate them ourselves during extraction.
  • Removed the logical_rect and physical_rect methods from Node the descriptions and namings are deceptive, it's better to create the rects manually instead.
  • Added a method outline_radius to Node that calculates the border radius of outlines.
  • For border values ExtractedUiNode takes BorderRect and ResolvedBorderRadius now instead of raw [f32; 4] values and converts them in prepare_uinodes.
  • Removed some unnecessary scaling and clamping of border values (Border radius is scaled incorrectly #15142).
  • Added a BorderRect::ZERO constant.
  • Added an outlined_node_size method to Node.

Testing

Added some non-uniform borders to the border example. Everything seems to be in order:

nub

Migration Guide

The logical_rect and physical_rect methods have been removed from Node. Use Rect::from_center_size with the translation and node size instead.

The types of the fields border and border_radius of ExtractedUiNode have been changed to BorderRect and ResolvedBorderRadius respectively.

@ickshonpe ickshonpe added A-UI Graphical user interfaces, styles, layouts, and widgets A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Sep 11, 2024
@ickshonpe ickshonpe changed the title precompute border values use precomputed border values Sep 11, 2024
@villor villor mentioned this pull request Sep 22, 2024
21 tasks
Copy link
Copy Markdown
Contributor

@UkoeHB UkoeHB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Can you update the example to include varied combinations of border width and border radius? Looks like it's all uniform right now.

@ickshonpe
Copy link
Copy Markdown
Contributor Author

Okay this should be ready now.

@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Sep 25, 2024
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 26, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 26, 2024
Merged via the queue into bevyengine:main with commit 0fe33c3 Sep 26, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 15, 2024
# 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen 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-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.

Border radius is scaled incorrectly

5 participants