-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split UI Overflow
by axis
#8095
Split UI Overflow
by axis
#8095
Conversation
* Split the UI overflow implementation so overflow can be set for each axis separately. * Added new enum `OverflowAxis` with `Hidden` and `Visible` variants. * Changed `Overflow` to a struct with `x` and `y` fields of type `OverflowAxis`. * `Overflow` has new methods `visible()` and `hidden()` that replace its previous `Hidden` and `Visible` variants. * Added `Overflow` helper methods `x_hidden()` and `y_hidden()` that return a new `Overflow` with the given axis hidden. * Added register type for `OverflowAxis`. * Changed the `ui` example to use `Overflow::y_hidden()` instead of `Overflow::Hidden`. * Modified `update_clipping` so it calculates clipping for each axis separately. If a node is only clipped on one axis, the other axis is given -/+ `f32::INFINITY` clipping bounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, I just pointed a couple of nits. 👍
crates/bevy_ui/src/update.rs
Outdated
// Update this node's CalculatedClip component | ||
match (clip, calculated_clip) { | ||
(None, None) => {} | ||
match (maybe_inherited_clip, maybe_calculated_clip) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: what do you think about switching the position to (before, after)
as in #8147? For me at least it's a tiny bit easier to understand:
(None, None)
=> noop(Some, None)
=> remove(None, Some)
=> add(Some, Some)
=> update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to switch them because it's a good idea, I like semantic ordering etc, but then I realised that it's probably better to use nested if let
statements as you avoid that which option is which ambiguity completely.
examples/ui/ui.rs
Outdated
@@ -111,7 +111,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |||
flex_direction: FlexDirection::Column, | |||
align_self: AlignSelf::Stretch, | |||
size: Size::height(Val::Percent(50.)), | |||
overflow: Overflow::Hidden, | |||
overflow: Overflow::y_hidden(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would maybe just use Overflow::hidden()
just to keep the same behavior as before. It's not really a problem unless children use an explicit width bigger than the container… which we know doesn't happen.
Ignore me (resolve this) as you wish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking Overflow::y_hidden()
is more expressive and intentional as it's a vertically scrolling list.
There is a lot to be said for only making minimal changes though and I get carried away sometimes 😅
I would like to add more cases to the overflow example. I'm thinking we either:
I prefer the first option since the example from this PR, as it is now, is very didactic. I want to test few cases related to images/text and related UV problems (see #8167), e.g.:
The axis-aligned/scaling cases should be solvable without major refactors (🤞). The rotation is going to be trickier. What do you think? |
* Cargo fmt * Overflow example clips a bevy logo image instead of a rectangle.
I'm happy enough with the example as it is now that the rectangle is replaced with a clipped image. I think if anyone has any ideas for improvement it would be better to wait till this is merged (if it is) and then open another PR. Not really sure about rotation and scaling and what we should support or how etc, there are still lots of bugs that need to be dealt with before we make big changes like that I think. |
# Objective - Add a new example that helps debug different UI overflow scenarios - This example tests the clipping behavior for images and text when the node is moved, scaled or rotated. ## Solution - Add a new `overflow_debug` example # Preview **Note:** Only top-left is working properly right now. https://user-images.githubusercontent.com/188612/227629093-26c94c67-1781-437d-8410-e854b6f1adc1.mp4 --- Related #8095, #8167 --------- Co-authored-by: Carter Anderson <[email protected]> Co-authored-by: ickshonpe <[email protected]>
I would like to suggest that the current
|
Yes, |
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
@ickshonpe I'm happy with this PR; can you please rebase? |
should be done now |
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ickshonpe I think you need to add a category to the example metadata to make CI happy.
@@ -1758,6 +1758,14 @@ description = "Illustrates how FontAtlases are populated (used to optimize text | |||
category = "UI (User Interface)" | |||
wasm = true | |||
|
|||
[[example]] | |||
name = "overflow" | |||
path = "examples/ui/overflow.rs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path = "examples/ui/overflow.rs" | |
path = "examples/ui/overflow.rs" | |
category = "UI (User Interface)" | |
wasm = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see you have already done this.
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
…/bevy into split-overflow-by-axes
Objective
Split the UI overflow enum so that overflow can be set for each axis separately.
Solution
Change
Overflow
from an enum to a struct withx
andy
OverflowAxis
fields, whereOverflowAxis
is an enum withClip
andVisible
variants. Modifyupdate_clipping
to calculate clipping for each axis separately. If only one axis is clipped, the other axis is given infinite bounds.Changelog
OverflowAxis
withClip
andVisible
variants.Overflow
to a struct withx
andy
fields of typeOverflowAxis
.Overflow
has new methodsvisible()
andhidden()
that replace its previousClip
andVisible
variants.Overflow
helper methodsclip_x()
andclip_y()
that return a newOverflow
value with the given axis clipped.update_clipping
so it calculates clipping for each axis separately. If a node is only clipped on a single axis, the other axis is given-f32::INFINITY
tof32::INFINITY
clipping bounds.Migration Guide
The
Style
propertyOverflow
is now a struct withx
andy
fields, that allow for per-axis overflow control.Use these helper functions to replace the variants of
Overflow
:Overflow::Visible
withOverflow::visible()
Overflow::Hidden
withOverflow::clip()