0 votes

Hello,
I'm currently designing my main menu. However, I can't wrap my head around how the HBoxContainer works. My Node hierarchy can be described as follows:

Menu Container (Type: Control) > HBoxContainer (Type: HBoxContainer) >
TextureRect (Type: TextureRect, SourceType: ImageTexture)

Whenever I add an image source which exceeds the container limits, my HBoxContainer is always resizing itself to fit the image. Furthermore I can't change the height or the width of it by any means. I don't know. Am I missing something?

in Engine by (14 points)

1 Answer

+1 vote

Whenever I add an image source which exceeds the container limits, my HBoxContainer is always resizing itself to fit the image.

This is exactly what I would expect from it. However, if you don't want this to happen, you should set the rect_clip_content-property to true on your "Menu Container"-node. Then, the rect_size of that node will define how much of the HboxContainer is rendered, the rest is simply cut off. If you want to scroll through it, change the type of your "Menu Container"-node into a ScrollContainer.

Furthermore I can't change the height or the width of it by any means.

If, by "it", you're referring to the HBoxContainer: Why would you want to do this in the first place? It scales automatically with the content.

If you're referring to the TextureRect: That's indeed a bit unintuitive. Setting the rect_size- or scale-properties won't have the effect you're likely going for. What you can do instead, is setting the expand-property to true, selecting "Keep Aspect" as a stretch_mode and then set rect_min_size to your liking.

by (10,580 points)

I'd like to add that the expand-property is NOT the v and h_expand properties under size_flags, but a property of the TextureRect class, at the top of the inspector. This cost me some time trying to figure out.

Unrelated, but "expand" seems like a bad choice of name for that property, since having it enabled also lets the TextureRect shrink, like I needed it to. "Resizeable" might be a better name for it.

But what if I want something that tiles, but also shrinks to the rest of the UI?

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.