A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Calling all New Unity users! Join the Halloween Mods Showcase Challenge until October 31.
Discussion in 'UIElements' started by TextusGames, Oct 6, 2019.
I am trying to autoexpand width of parent that has a child label component according to text width?
Parent elements will by default accommodate child elements. The only time this doesn't work is if the parent element has a fixed width already applied, or a flex-grow/flex-shrink style.
I tested with new uiBuilder and was not able to achieve this.
Actually height of parent is inhereted from child.
But how can parent inheret width of child?
I think you're running into the fact that the root element (in the Builder's case, it's the Canvas element), which you have no control over, has Align > align-items: stretch;, by default. This makes children that have no explicit width stretch to take up the entire row. You can fix this by adding an extra VisualElement parent (essentially your own root), and setting its Align > align-items: flex-start;. See pic:
grandparent: blue - align-items: flex-start;
child: red width: 200px;
Thanks the issue was the stretch alignment of parent.
Now i undestand how it works.