Search code examples
godot

Godot add optional left padding to VBox control node?


How can I add optional padding to a VBox control node without having the padding expand the minimum space the entire VBox node takes up?

For example, the layout should normally look like this:

| padding | VBox content | 

But when there's not enough space, the padding can shrink

| padd | VBox content |

All the way down to 0

|| VBox content |

I tried using a margin container, but the margin will not shrink.


Solution

  • Instead of

    VBox
    '-HBox
      '-Optional padding left
      '-VBox
        '-Content
        '-Content
        '-Content
    

    I did

    VBox
    '-VBox
      '-HBox
        '-Optional padding left
        '-Content
      '-HBox
        '-Optional padding left
        '-Content
    

    The RectMinSize on the padding is set to 0 horizontally, so the padding can shrink all the way down to nothing. I then set the horizontal size flags of each content and padding to SizeFlags.ExpandFill, and I have the SizeFlagsStretchRatio of the padding set to 0.1, and for the content, it's set to 1. This way, the padding will normally take up a small, fixed % of the space but can still shrink down to 0.

    However, I still haven't found a way to make fixed-length padding shrinkable. But for now, I'm happy with using ratio-based shrinkable padding.