How can I vertically center all items in a GridContainer?
Asked Answered
B

9

0

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?

Badoglio answered 3/4, 2023 at 7:0 Comment(0)
T
0

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

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

Tedmann answered 4/4, 2023 at 9:9 Comment(0)
T
0

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

Tedmann answered 3/4, 2023 at 14:47 Comment(0)
B
0

Tedmann 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,

Badoglio answered 4/4, 2023 at 3:23 Comment(0)
B
0

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

Bite answered 4/4, 2023 at 3:53 Comment(0)
L
0

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

Limitless answered 4/4, 2023 at 6:7 Comment(0)
W
0

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.)

Wellbalanced answered 4/4, 2023 at 6:44 Comment(0)
T
0

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

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

Tedmann answered 4/4, 2023 at 9:9 Comment(0)
B
0

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

Badoglio answered 4/4, 2023 at 9:14 Comment(0)
B
0

Limitless Yes this work. Thanks!

Badoglio answered 4/4, 2023 at 9:17 Comment(0)
B
0

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

Badoglio answered 4/4, 2023 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.