• Godot HelpGUI
  • How can I vertically center all items in a GridContainer?

I have a label and a progress bar in a GridContainer and this GridContainer is inside a HBoxContainer.
How can I vertically center all items in this GridContainer?

  • xyz replied to this.
  • newguy Put a HBoxContainer inside GridContainer. You did the opposite. So:

    GridContainer
    --- HBoxContainer
    ------ Label
    --- ProgressBar

    newguy Additionally contain the label within vertically expanded or center shrinked HBoxContainer.

      xyz Thanks for help. I tried to contain the GridContainer with a new vertically expanded or center shrinked HBoxContainer but nothing happens. Here's how my scene tree look like,

      • xyz replied to this.

        You need to set GridContainer column to 1 for it to stack vertically.

          You can add spacers. Just add a control node above and below what you want to center and set them as expand fill.

            This video from GDQuest might help you.

            By the way, you didn't give which Godot version you're using, 3.5 and 4.0 doesn't not manage containers the same way, and AFAIK, we need to give a custom minimum size at one point because containers are unable to calculate one themselves, even and especially when they have some content which have a defined size (label or texture for instance.)

            newguy Put a HBoxContainer inside GridContainer. You did the opposite. So:

            GridContainer
            --- HBoxContainer
            ------ Label
            --- ProgressBar

              Gowydot Yes but what I need is for both items to vertically center not vertically stack.

              xyz Yes this work well and the progress bar has to be inside a HBoxContainer too. Thanks!