Set AutomaticSize to only fit to TextBounds

As a Roblox developer, it is currently too hard to use AutomaticSize with TextLabels.
I use AutomaticSize to make sure my TextLabels wrap tightly with currency amounts. Then as a child of the TextLabel I add an ImageLabel to show which currency the amount is in.

If Roblox is able to address this issue, it would improve my development experience because this behavior prevents me from being able to easily center text with an image offset of the TextLabel.

DSF4OmV32C

This is inconvenient because it causes text to feel off-center. Here is what it looks like with AutomaticSize:
image

What I want it to look like (text is centered with button)
image

9 Likes

Hi @Usering - from what I understand, it sounds like you want to be able to automatically size just the TextLabel and ignore child hierarchy from the automatic sizing, is that correct?

One possible way of achieving this is that we could add a constraint to omit an object from automatic sizing, or perhaps new automatic size enum values where child hierarchy is ignored.

With the constraint, the hierarchy would look something like this:

  • TextLabel
    – Coins
    — AutomaticSizeConstraint

I’d have to think about this some more, as I’m not sure this approach would work in all cases…

5 Likes

from what I understand, it sounds like you want to be able to automatically size just the TextLabel and ignore child hierarchy from the automatic sizing, is that correct?

Yep that’s the case I need here. From what I could find, Roblox has no AutomaticSizeConstraint object. It’s just a property of any GuiObject that applies to all of its children, as well as whatever content it has itself.

1 Like

I ran into this issue too. It was how I was expecting AutomaticSize to work with TextLabels.

A solution for this visual in the meantime:

  • Put the TextLabel and icon in a Frame
  • Add a horizontal UiListLayout to the Frame
  • Turn AutomaticSize on for the TextLabel
2 Likes

Thanks all for the feedback and request! I’ve created a ticket to investigate this. For now, the solution suggested by @Polyhex - to use a UIListLayout - is your best option.

2 Likes

Thanks for the suggestion. That ends up with the same result as the issue I’m running into; the text is off center with the rest of the button. Hopefully this can be resolved soon!

I’m sorry for bumping this but I think UISizeConstraint would be necessary for a case like this:

image

I find this as frustrating as UISizeConstraint supports only Offset and I would like if it would support Scale as well.