How to shrink Control dynamically?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fhgaha

I have a PanelContainer with HBoxContainer as child and HBoxContainer has several children. When size of HBoxContainer’s children change PanelContainer grows. I want PanelContainer to stay as small as possible.
In Remote if I slightly change (even to one) any of margin properties of PanelContainer it shrinks to the smalest size which is what I want but if I change margin in code it doesn’t work out.

Have you tried messing around with the Control anchors? For instance, try setting the anchor pins to a certain size so that the Control doesn’t grow any larger than that. Either that, or mess around with the anchor properties in the Control.

Ertain | 2021-06-25 19:46

:bust_in_silhouette: Reply From: fhgaha

I found you can make Control type node shrink like that:

func _process(delta): 
margin_right -= 1
margin_right += 1