Search Issue Tracker
Feature Request
Votes
0
Found in
2023.1.0a3
Issue ID
UUM-8198
Regression
No
Adding a VisualElement child to a Label breaks the Label's worldbounds and flex behavior
From a Forum user (https://forum.unity.com/threads/adding-a-visualelement-child-to-a-label-breaks-the-labels-worldbounds-and-flex-behavior.1303740/):
In UI Toolkit, if you add a child VisualElement to a Label, it breaks the Label's worldbounds and flex performance. Instead of the worldbounds representing the Label, they will be representative of the child that was added to it. The Label will no longer flex or layout properly.
This is demonstrated in a simple bug report project I made (IN-911).
1) When there is no child attached to the red Label (public bool on "UIDocument" set false) it lays out fine. The red background of the Label fills the Label space and the bounds are calculated correctly.
childoflabel1.png
!image-2022-07-06-16-57-30-980.png|thumbnail!
2) When a child is added to the red Label (simple cyan square) it breaks the Label's layout. The red background of the Label no longer fills the Label space and now conforms to the cyan square child.
childoflabel2.png
!image-2022-07-06-16-57-46-765.png|thumbnail!
This can be worked around by avoiding adding children to Labels, but sometimes it is desirable to position a visual element relative to a label (eg. a text cursor or caret or box around a word) and having to the child instead it to a different element requires extra calculations to offset it correctly.
It would be helpful if we could position children directly relative to a Label as the Label's children without breaking the Label. Thanks.
I am not sure if this is already known, but I found this problem once before, and now lost 3-4 hours today again before figuring out it was the problem again. I presume this is not intended behavior and although it is not crippling (I can work around it), it might be nice to have it fixed, and perhaps you are not already aware.
Note: Problem seems to be apparent when the Label's white-space property is set to "normal".
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
Resolution Note:
We plan to allow TextElement to have embedded VisualElement and this is a feature we will tackle in the future.