3

I admit I have not been using godot for very long but I cannot seem to get control nodes to act predictably. I have been able to get close but not with a color background. I tried adding a colorRect and then godot goes completely bonkers. I do not understand how it could have results like that. I have tried every random combination of controls I can think of.

enter image description here

on the left is a broken version with a colorRect. the one on the right is as close to what I want but does not have a colorRect. for some reason the colorrect has completely evaporated. also removing a child node on left does not remove it completely. on the right the children stack properly in the vboxcontainer but on the left, the children stack on top of each other. the row is its own scene, it contains a child scene. that scene has the first scene as children.

I have no idea how to troubleshoot this.

enter image description here

Here is the scene tree for the almost working one on the right.

enter image description here

here is the scene tree for one of the many attempts to add a background color.

I hope someone knows how to do this.

***EDIT Is there a control that works like a jpanel? is there a way I can get access to the layout manager?

***EDIT why does the layout manager in a Container not work like the layout manager in a hboxContainer?

***EDIT enter image description here ColorbrickNode is inside of an hbox. that hbox has only two children. those two children should be half of the width of the hbox. look at the size of colorbrickNode, the +- buttons are children of it. how should this be working? how can children be outside of the confines of a control and still be visible?

Goff
  • 343
  • 1
  • 3
  • 14
  • 1
    Have you tried having a vanilla `Control` node as the parent, and then giving it two children? First is your color rect, second in your VBoxContainer – JarWarren Jun 21 '22 at 00:36
  • Hello, yes I have tried a basic control node. the +- buttons end up off the screen and the colorrect turns into a line a good bit above the actual scene that created it. – Goff Jun 21 '22 at 00:41
  • "how can children be outside of the confines of a control and still be visible?" The property `rect_clip_content` controls that. – Theraot Jun 23 '22 at 01:50
  • 2
    Please consider bringing these issues to https://github.com/godotengine/godot-proposals/discussions or if you think you found a bug make a minimum project showcasing it at submit it to https://github.com/godotengine/godot/issues – Theraot Jun 23 '22 at 01:55
  • That is a good point. Container does not work correctly but, MarginContainer has the functionality that Container should have. – Goff Jun 24 '22 at 18:42

2 Answers2

2

enter image description here I got it. I used a margin container. why does a margin container have the functionality but a vanilla container does not have? who knows. why is there a margin container when every container has the ability to set margins? who knows. A margin container has the ability to set the size of its children. a margin container has the ability to have children components stack on top of each other. a margin container should be the default container. the name is very misleading. it is not graphicaly perfect but it is very close.

Goff
  • 343
  • 1
  • 3
  • 14
  • I see. Yeah, I don't know why you would need a `MarginContainer`. Still, people might find your answer useful. +1. – Theraot Jun 23 '22 at 01:49
1

I think I understand the issue. At least why the ColorRect turns to a line. I'm assuming you have set its layout to "Full Rect", right? Guessing. But you have NOT set its size flags.

When the ColorRect inside a container, that container is what will dictate how it is sized and positioned. In this case the container is a HBoxContainer, right? I'm not sure where you are adding the instances, I'm guessing here. A HBoxContainer would set its children as columns. So they take the full height, as we see the ColorRect do. And to decide how much horizontal space it takes… Well, it takes as little as possible, so you get a line.

The VBoxContainer inside the ColorRect, on the other hand, has a minimum size. So it overflows the ColorRect. Yes, we could imagine that could set its minimum size based on its contents… Except, it is not Container.

Now, to tell a Container (such as the HBoxContainer) to size its children differently, you would set the size flags of said children.


I have covered how Controls are positioned and sized in more detail in other answers here and here.

Theraot
  • 31,890
  • 5
  • 57
  • 86
  • I do apologize, but I still do not know what to do. In the working one, the root is a vbox, an hbox is inside that. the label and buttons are inside the hbox. instances are placed into the vbox under the hbox. I want the colorRect to have the exact same size and position as the vbox, even if it gets resized. I am a java programmer and I would do this with a layout manager in a jpanel. what kind of hierarchy do I need? the scene "brickNode" is instanced in another scene that can resize it with a hsplitcontainer. the vides I watched were light on UI elements. Is there a node that has a z order? – Goff Jun 22 '22 at 00:28
  • @Goff From the picture I'm guessing you are adding the scene instances to a `VBoxContainer` (so each instance of the scene is a row), which I'm now guessing it is inside a `HSplitContainer`. I had the idea that you were adding the instances inside of each other, kind of like a tree structure. If that is not the case, then I don't know why you have a `VBoxContainer` in the scene (it is only one row after all). Anyway, regardless, I believe making the `ColorRect` the root is correct. You would need to 1. Set size flags on the `ColorRect`, and 2. set the layout of container inside to full rect. – Theraot Jun 22 '22 at 14:36
  • is there a way I can post a zip of the project? – Goff Jun 22 '22 at 17:05
  • I would like to thank you for your effort on this problem. – Goff Jun 23 '22 at 01:43