Overflow clip margin#15561
Merged
alice-i-cecile merged 66 commits intobevyengine:mainfrom Oct 16, 2024
Merged
Conversation
…ourselves in each extraction function which is really complicated and fragile and has lead to a number of bugs. Adds an `Inset` type, a `border: Inset` field to `Node`, updates the border field in `ui_layout_system`, and removes the border calculations and extra queries from the extraction functions.
…der values instead.
Co-authored-by: UkoeHB <[email protected]>
Fixed `outline_radius` comment.
nicoburns
approved these changes
Oct 1, 2024
Contributor
nicoburns
left a comment
There was a problem hiding this comment.
Looks good to me. Web only implements this for overflow:clip (not hidden or scroll). Not sure what the reasons for that is.
Merged
BenjaminBrienen
approved these changes
Oct 13, 2024
Contributor
|
Really nice showcase |
…ns with a method on self.
…ns with a method on self.
UkoeHB
approved these changes
Oct 14, 2024
Member
|
This going to have merge conflicts with its sibling PR, but ping me tomorrow and I'll get this in. |
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]>
Contributor
Author
Weren't too bad, should be ready now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Limited implementation of the CSS property
overflow-clip-marginhttps://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-margin
Allows you to control the visible area for clipped content when using overfllow-clip, -hidden, or -scroll and expand it with a margin.
Based on #15442
Fixes #15468
Solution
Adds a new field to Style:
overflow_clip_margin: OverflowClipMargin.The field is ignored unless overflow-clip, -hidden or -scroll is set on at least one axis.
OverflowClipMarginhas these associated constructor functions:You can also use the method
with_marginto increases the size of the visible area:with_marginexpects a length in logical pixels, negative values are clamped to zero.Notes
margin-boxoption but we don't have access to the margin values inNodeso it's probably not feasible to implement atm.Testing
cargo run --example overflow_clip_marginMigration Guide
Style has a new field
OverflowClipMargin. It allows users to set the visible area for clipped content when using overflow-clip, -hidden, or -scroll and expand it with a margin.There are three associated constructor functions
content_box,padding_boxandborder_box:content_box: elements painted outside of the content box area (the innermost part of the node excluding the padding and border) of the node are clipped. This is the new default behaviour.padding_box: elements painted outside outside of the padding area of the node are clipped.border_box: elements painted outside of the bounds of the node are clipped. This matches the behaviour from Bevy 0.14.There is also a
with_marginmethod that increases the size of the visible area by the given number in logical pixels, negative margin values are clamped to zero.OverflowClipMarginis ignored unless overflow-clip, -hidden or -scroll is also set on at least one axis of the UI node.