-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
base: main
Are you sure you want to change the base?
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.
… switching between corner-based and object-centered coords. `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).
Check transform is invertible before transforms to node space.
@alice-i-cecile I think this is more or less good enough now. Abandoned the weird ideas I had, just got a |
…bevy into node-global-transform
Objective
Add specialized UI transform components 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
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.