I’m making an inventory panel. My base resolution is low at 320x180. When I scale the resolution up to 1920x1080, the buttons bunch up and have some funky positioning.
Here’s my scene tree and how the anchors are positioned.
making a bunch of dummy nodes until it reaches the right amount of buttons to display things properly. After that, adjusting them to flat and disabling them. It achieves what I’m looking for, though it makes a scroll bar that’s not needed at the base resolution.
Seem like your buttons just collapse on each other, try adjusting their custom_minimum_size property.
This is my quick setup I did, it seems to work fine with any resolution and any amount of buttons. I didn’t even need to adjust the custom_minimum_size property.
Did you try adjusting the custom_minimum_size? (especially y (height) component is important).
Without any text, the Button’s size will collapse. It doesn’t matter that the Button has children, it’s not a Container, so it ignores children. That’s why you need the custom_minimum_size.
I recreated your setup, below are the screenshots:
Hey I see it is indeed collapsing. At a higher resolution I had to set it to about 45 pixels in the y component to display normally (I’ll show the pictures of before and after).
@tool
extends Container
func _notification(what):
if what == NOTIFICATION_SORT_CHILDREN:
var button = get_child(0)
var label = button.get_child(0)
size.y = label.size.y
fit_child_in_rect(button, Rect2(Vector2.ZERO, size))
The container’s set to expand horizontally in the editor. Then I’m setting the height of the container to the height of the label. I fit the button to the container’s size. It works fine when growing the window, but I see through print statements when I shrink it back down the y-size of the label doesn’t change so the button has an inappropriate height. I’m not too sure why.
When I get rid of size.y = label.size.y, the label’s y-size grows and shrinks like normal. I can’t think why that’s getting in the way of it shrinking.
Making item buttons like this, though, works fine. It doesn’t feel as clean but it gets what I’m going for. I put everything underneath a label.
I honestly don’t understand what the problem is now, so if you still need some support there, you’d need to try rephrasing it, because you lost me, sorry
Just one think comes to mind that you can try to see if the NOTIFICATION_SORT_CHILDREN fires with a print() statement when you shrink your container.
That’s ok. There were other things I wasn’t sure how to do with the container that were looking weird, like items clipping in to each other vertically. I set a label as the parent node instead of a button and it sizes things correctly!