#Container whose contents automatically scale to fit

1 messages · Page 1 of 1 (latest)

near charm
#

I have very little experience with frontend/graphic design/etc stuff so sorry if this is obvious!

But like the title says, I want a container such that anything inside the container is automatically scaled to fit. I am hoping there is some obvious basic solution to this that I'm missing. For example, if I have a square container that contains a label, then the label is scaled (maintaining its proportions, so no flattening or narrowing) such that its sides are touching the bounds of the container. I am hoping I won't have to implement this myself, but I'd just like to know either way.

foggy terrace
#

I think what you're looking for is a PanelContainer. You can set a custom anchor preset and choose which direction the panel should grow (based on the child, so in this case a label, which can also have word wrapping settings to further achieve what you're looking for) or shrink based on what is contained within. You can also set a minimum size to the container so it has a presence before growing, meaning it won't just appear out of the blue whenever content is filled into the children

near charm
#

Hmmm this doesn't work when it comes to having a label inside... I think I might have to write my own script to make text behave this way

#

I've gotta figure it out one way or another. It just seems like such a basic design mechanic, yknow? Scale to fit container

#

Like, here's a simple example: how would one create a label with a single letter "A", and have it so no matter how you resize the game window, the A always fills it.

near charm
#

Okay, after looking into this more, I feel fairly certain I'm gonna have to implement this myself. The problem is that label text is determined entirely by font size, it seems. So there's probably no way to do this other than writing my own code for automatically changing the font size to fit the label's container

#

Hopefully won't be toooo hard, I can build an expression that calculates the correct font size so long as I can access the dimensions of label's container

near charm
#

(Actually ended up being a fun engineering problem. Might even do a little writeup about it, if I do then I'll share it here in case anyone's interested.)