Replies: 2 comments 2 replies
-
Someone replied on the forum suggesting to extend Container directly in project code, and indeed that would allow us to make it work as a simple project script rather than in native code (well could technically be a native extension too), so not sure if I should open a proposal for it. Maybe I'll have a look at it later, I'll have to adapt CenterContainer, PanelContainer, MarginContainer's native code to GDScript though. Ultimately if this can be done on C++ side reusing similar code, it would probably be even better. |
Beta Was this translation helpful? Give feedback.
-
I need this too. I have big trouble in making control layouts because (1) Godot seems to have difficulties with containers, and (2) I would need to write big low level code to fix it. I have very simple begin but very big problems! I remember GTK had much more intuitive container handling - as it should be intuitive in Godot too. I'm looking at a few control node projects, if they give me ideas. It is already extra work for me, but I hope to find a GD script-only solution. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I opened this question on the forum:
HBoxContainer/VBoxContainer: intermediate Control parent nodes have size X/Y = 0, how to auto-fit to children size?
https://forum.godotengine.org/t/hboxcontainer-vboxcontainer-intermediate-control-parent-nodes-have-size-x-y-0-how-to-auto-fit-to-children-size/53527/1
and currently, there is no easy way to create an intermediate parent Control that would have one or many children, that would be resized automatically to the children's size (maximum bounding box) so it can be used under HBoxContainer/VBoxContainer or event GridContainer and FlowContainer: when the size along the container direction is 0, elements are not properly placed one after the other.
To reuse images from my question post:
will result in:
(all images overlap)
instead of:
I found a few solutions that work well when you know the size in advance, but won't auto-update if image assets change later:
However I'd like a dynamic way to keep the Control parent fit the children size.
I found out that I could use Container child classes (since base Container class does nothing), and they do fit to children size, but there are two issues:
So it would be nice to have either an option on the base Control node to fit children size (but may be too intrusive and will be useless on Container child classes which already do this), or my main suggestion:
add a more generic Control child class specialized in fitting children size (maximum bounding box)
Since we don't want a Container to allow child offset, it would inherit directly from Control, maybe named “ChildFittingControl” or so.
Or is it impossible to have a non-Container Control node know about its children?
I remember I had the same issue in Unity, but I think in the end I managed to find a way to take child dimensions into account (expand parent UI element to children) without actually spreading them over the whole container (there were probably more alignment options so I could maintain top-left alignment in the end).
Beta Was this translation helpful? Give feedback.
All reactions