I have this:
I’d like it to shrink when the foldout is collapsed
I have everything under a group that is set to “shrink” but that doesn’t seam to do anything.
I have this:
I’d like it to shrink when the foldout is collapsed
I have everything under a group that is set to “shrink” but that doesn’t seam to do anything.
The Foldout
control will automatically show/hide anything that is under it in the hierarchy. You can drag the content inside the Foldout
if you’re working in the UI Builder, or from code add your content with a simple foldout.Add(yourContent)
Yes but the group box that is a parent of the foldout doesn’t shrink. I can make it “Expand” by having the parent start smaller and then it will “Grow” with the child foldout but the parent groupbox wont “Shrink” with its child.
Not too sure what you mean by the parent group box, but you can react to the value changes of the Foldout by registering a callback like so:
foldout.RegisterValueChangedCallback(evt => Debug.Log($"Do something with the new value: {evt.newValue}"));
You could play with the size of the parent in there.
I expected the parent would auto shrink as children were removed/hide but that is not the case. If you undersize the parent groupbox to be size you want it to be when its “fully collapsed” it will however EXPAND as the foldout expands or children are added. It just means you can’t use the wysiwyg editor for spacing of children.
E.g. in my picture above with all the blank space that blank space will not collapse even though their is nothing in it. However if I shrink the starting area it will expand as stuff is added. So its just inconsistent behavior between grow and shrink. The parent will never shrink below its initial size due to child interaction but it will grow beyond its initial size.
Ah I think I get what you mean now. Sorry about that, I didn’t realize you were talking about the purple-grey-ish container.
Something is preventing the container from shrinking, but it’s not the foldouts. You can use the UI Toolkit Debugger to see what drives the value of the container.
What are the parent container style settings?
Does it have flex-grow: 1
or flex-shrink: 0
? Or a min-height
set? That would cause the container to take more space than necessary when you want it to match the foldout size.