0 votes

I have a ScrollContainer with an HBoxContainer inside. On ready, I have a script which iterated through a folder and creates a button corresponding to each file in the folder. For each file (FileName) in the folder it runs the following code:

    var button = Button.new()
    button.connect("pressed", self, "_which_button_pressed", [button])
    button.size_flags_vertical = 3
    button.rect_size.x = button.rect_size.y * 2

But the buttons are not coming out the way I want. They end up tall and skinny and ignore the

     button.rect_size.x = button.rect_size.y * 2

as if it is overriden by something. I can't figure out how to do what I want, which is to have the button be exactly the height of the HBoxContainer it is inside of but stretch itself so that its aspect ratio is always 2:1. I must be missing something simple here. Thanks.

in Engine by (47 points)

1 Answer

+2 votes
Best answer

Try setting the rect_min_size instead of rect_size

Pretty sure parent containers rewrite the rect_size however they think it should be, but will honour the rect_min_size

If the available size is greater than the rect_min_size I'm not sure how it'll upscale things.

You could also try setting the rect_scale directly?

by (182 points)
selected by

I solved it by simply setting the x value of the button's rectminsize to twice the value for the container's recsize.y. Thanks for telling me about the rectmin_size property as I had completely forgotten about it in this scenario.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.