-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Specialized UI transform #16615
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
Specialized UI transform #16615
Conversation
* Required `GlobalTransform` instead of `Transform` on `Node`. * Update node's global transforms during layout updates.
…bevy into node-global-transform
I like this as an incremental move forward. We shouldn't be storing a full Should this be on |
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
This does seem like the least-bad option. But I thought there was code in I believe this should fix the issues |
The new transform field on I made another branch first just before this one that removed both |
I haven't seen anything like this. Afaik the only way to opt-out of transform propagation is by removing |
…lue in physical pixels. This required adding an extra parameter for the scale factor.
thanks that's great, I was just about to go and beg on discord for someone to review this |
Added `compute_affine` function
…bevy into node-global-transform
@@ -324,12 +393,12 @@ impl From<Vec2> for ScrollPosition { | |||
#[require( | |||
ComputedNode, | |||
ComputedNodeTarget, | |||
UiTransform, |
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.
Just an idea. You could make Node
depend only on UiGlobalTransform
, making UiTransform
an optional component.
The only difference would be using Option<&UiTransform>
instead of &UiTransform
in ui_layout_system
, saving a call to compute_affine
when the component is not present.
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 think we may want to consider folding GlobalZIndex
and ZIndex
into the UI transform eventually. Would appreciate your thoughts on the plan sketched out here.
I'm not sure this solves the problem I have been having with pointer interactions for multi-part widgets. Consider a slider with a draggable thumb: you click on the thumb entity, so the picking event you get has the coordinates relative to the thumb. But what you need for the drag calculation is the coordinates relative to the slider as a whole. What I'd like is for the observer function to have the option to transform the picking coordinates into local coordinates for any arbitrary ancestor of the picked element. The easiest way to do this, I think, is to have the event contain global coordinates, and then have the observer do a conversion to local coordinates using the global transform component on the ancestor. |
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
# Objective This example migration was missed in #16615 https://pixel-eagle.com/project/b25a040a-a980-4602-b90c-d480ab84076d/run/10633/compare/10627?screenshot=3D+Rendering/pbr.png ## Solution Use new `UiTransform` ## Testing `cargo run --example pbr`
Objective
Add specialized UI transform
Component
s and fix some related problems:Transform
component of UI nodes doesn't work very well becauseui_layout_system
overwrites the translations each frame. Theoverflow_debug
example uses a horrible hack where it copies the transform into the position that'll likely cause a panic if any users naively copy it.CalculatedClip
is wrong for rotated and scaled elements.Transform
doesn't support responsive coordinates.Solution
Transform
fromNode
.UiTransform
,UiGlobalTransform
:Node
requiresUiTransform
,UiTransform
requiresUiGlobalTransform
UiTransform
is a 2d-only equivalent ofTransform
with a translation inVal
s.UiGlobalTransform
newtypesAffine2
and is updated inui_layout_system
.ComputedNode
for mapping between viewport and local node space.RelativeCursorPosition
's coordinates are now object-centered with (0,0) at the the center of the node and the corners at (±0.5, ±0.5).normalized_visible_node_rect: Rect
field ofRelativeCursorPosition
withcursor_over: bool
, which is set to true when the cursor is over an unclipped point on the node. The visible area of the node is not necessarily a rectangle, so the previous implementation didn't work.This should fix all the logical bugs with non-axis aligned interactions and clipping. Rendering still needs changes but they are far outside the scope of this PR.
Tried and abandoned two other approaches:
transform
field onNode
, requireGlobalTransform
onNode
, and unrequireTransform
onNode
. UnrequiringTransform
opts out of transform propagation so there is then no conflict with updating theGlobalTransform
inui_layout_system
. This was a nice change in its simplicity but potentially confusing for users I think, all theGlobalTransform
docs mentionTransform
and having special rules for how it's updated just for the UI is unpleasently surprising.transform
field onNode
. UnrequireTransform
onNode
. Newtransform: Affine2
field onComputedNode
.This was okay but I think most users want a separate specialized UI transform components. The fat
ComputedNode
doesn't work well with change detection.Fixes #18929, #18930
Testing
There is an example you can look at:
Sometimes in the example if you press the rotate button couple of times the first glyph from the top label disappears , I'm not sure what's causing it yet but I don't think it's related to this PR.
Migration Guide
New specialized 2D UI transform components
UiTransform
andUiGlobalTransform
.UiTransform
is a 2d-only equivalent ofTransform
with a translation inVal
s.UiGlobalTransform
newtypesAffine2
and is updated inui_layout_system
.Node
now requiresUiTransform
instead ofTransform
.UiTransform
requiresUiGlobalTransform
.In previous versions of Bevy
ui_layout_system
would overwrite UI node'sTransform::translation
each frame.UiTransform
s aren't overwritten and there is no longer any need for systems that cache and rewrite the transform for translated UI elements.RelativeCursorPosition
's coordinates are now object-centered with (0,0) at the the center of the node and the corners at (±0.5, ±0.5). Itsnormalized_visible_node_rect
field has been removed and replaced with a newcursor_over: bool
field which is set to true when the cursor is hovering an unclipped area of the UI node.