Nesting VBoxContainers (like a Tree)
Asked Answered
H

13

0

I'm looking to nest VBoxContainers in a tree-like fashion. I know that Tree nodes exist, but it seemed like I could only make buttons, not add content like I want (unless I'm missing something). Right now, I have a nested structure kind of like this:

However, since the inner VBoxContainers aren't respected in each CardChoiceSection's height, the children of each CardChoiceSection overlaps with the parent container's siblings. Ideally I'd want it to look something like this:

But it currently looks like this:

Where the structure should be

  • Section 1
    • List (gray panel container)
  • Section 2
    • Treasure
      • List
    • Monsters
      • List
Hag answered 17/11, 2023 at 1:18 Comment(0)
S
0

Hag How deep does the tree go? Do you only ever have one sub-section and therefor only one level of indentation or can you have more than one?

One possible solution would be to just fake it and add an empty spacer element that is fully transparent but has a certain width so that it takes some space and indent a sub-section. And then just add as many spacers as there are indentation levels.

Scrofulous answered 17/11, 2023 at 4:26 Comment(0)
S
0

Can you give us a screenshot of your scene tab? Nested vboxes seems to be respecting height for me but I may not be doing what you're doing.

Saucepan answered 17/11, 2023 at 5:53 Comment(0)
S
0

Scrofulous I have no idea if Godot handles this well or if it will perform terribly, but MarginContainers can be used for indenting.

I have a theme set at the root which applies a left margin of 32

Saucepan answered 17/11, 2023 at 6:5 Comment(0)
S
0

Saucepan I have no idea if Godot handles this well or if it will perform terribly, but MarginContainers can be used for indenting.

Right, that would be another good way to do it.

Scrofulous answered 17/11, 2023 at 6:56 Comment(0)
H
0

Thanks for the suggestions! I'll include a little more information.

I have a CardChoiceSection scene that is laid out like this:

The title bar is fill horizontal and shrink begin vertically, and the ChildrenContainer and Children are both fill (with expand whenever it's possible.

At runtime, these CardChoiceSections are added to the tree with one or multiple CardChoiceSections in the Children VBoxContainer or a single CardChoiceList in Children.

The CardChoiceList looks like this

The Control is fill and expand in both directions and both that and the grid are FullRect anchors.

So imagine my structure is:

  • CardChoiceSection (Section 1)
    • CardChoiceList
  • CardChoiceSection (Section 2)
    • CardChoiceSection (Treasure)
      • CardChoiceList
    • CardChoiceSection (Monsters)
      • CardChoiceList

The tree would look like this (there is an extra CardChoiceSection wrapping the whole thing, I plan to remove that):

Okay...that was a lot sorry 😛 Hopefully it all makes sense.

Now to my question. I've since realized that my initial question wasn't asking the right thing. The size of the children is being respected (and thanks for the info about the margin container, I've just switched to that!), but the size of the children is always 0. My CardGrid has 8 columns and the sprites inside of it size like so (texture is added at runtime)

However, if our Children only contains a CardChoiceList, the height is 0:

It works perfectly if I set a Custom Minimum Size, but this whole thing is dynamic (things can be added and removed) and in a scroll bar, so I'm a bit confused on how to do that without hard coding a minimum size.

Any info helps, sorry for the extremely drawn-out post!

Hag answered 17/11, 2023 at 15:35 Comment(0)
C
0

Hag so I'm a bit confused on how to do that without hard coding a minimum size.

IMO, you should always have a minimum size, even if just 1 px otherwise why even have the element there at all if it's going to be 0 px?

Caloyer answered 17/11, 2023 at 18:16 Comment(0)
H
0

Caloyer That's super valid, but I should have clarified that it works perfectly if I set the minimum size to a certain value. Imagine my CardChoiceList grid has 9 items (so 8 on the first row, 9 on the second), then one gets removed. If the minimum height stays the same, there will be a bunch of blank space. But if it's only the height of one row, everything would be either shrunk or cut off.

Hag answered 17/11, 2023 at 18:27 Comment(0)
S
0

Nurseryman Is there any need for the regular Control at the root of CardChoiceList? I have a feeling that if you made CardGrid the root of that scene, your issue would be solved, but I haven't tested that yet.

Saucepan answered 17/11, 2023 at 20:28 Comment(0)
H
0

Saucepan I originally had GridContainer as the root, but the problem was that it meant Layout Mode was Uncontrolled, and at runtime it got set to Position instead of Anchors. Is there a better way to solve that?

Hag answered 18/11, 2023 at 21:54 Comment(0)
S
0

Hag Doesn't that make no difference if the GridContainer is the child of a VBoxContainer?

If there is another place you are also instantiating the same CardChoiceList scene but without the VBoxContainer parent? If that happens to be the issue, you could make another scene that is just a Control with the childed CardChoiceList scene in it. That way you'd have an option for both needs.

Saucepan answered 19/11, 2023 at 6:34 Comment(0)
H
0

Saucepan There isn't another place I'm instantiating it. I guess I'm a little confused. I am hoping to find a way where the GridContainer will size itself using the full width of the VBoxContainer and whatever height it needs (say, for 3 rows of cards in the CardChoiceList), then the VBoxContainer would auto-resize whenever necessary (say, when a 3 rows changes to 2 rows).

Hag answered 20/11, 2023 at 3:48 Comment(0)
S
0

If the GridContainer is always only ever the child of a VBoxContainer, then Position vs Anchors doesn't even matter, because its position and sizing is being controlled by the VBoxContainer. I think you just need to set a minimum size for the CardGrid and have that GridContainer as its scene root. Containers automatically respect the sizing of child containers. Having a normal Control in there is what is getting flattened.

Saucepan answered 20/11, 2023 at 7:14 Comment(0)
H
0

Saucepan That makes sense. I'm unsure how to get the minimum size for the CardGrid, though. I'm pretty unsure of the order stuff works in, so I'm not sure how to do it through code. Since the sizes of the cards within the CardChoiceList are determined by the CardChoiceList, and the minimum size of the CardChoiceList in theory would be a single row of cards (so, determined by the height of the cards), I'm not sure which order I should do things in.

For reference, I have removed the control node and made GridContainer the root of the CardChoiceList scene. Now everything has a height of 1, including the cards.

Thank you so much for your advice by the way!

Hag answered 22/11, 2023 at 1:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.