TextLabel TextBounds + UIScale Inaccurate


As shown above, when using a UIScale, the TextLabel’s TextBounds are inaccurate. The text overflows, even when the TextLabel’s size matches the TextBounds’ given size. Enabling TextWrapping does seem to make the text fit inside of the TextLabel’s visual bounds, but this is not the effect I am after.

The UIScale is scaled appropriately based on the user’s resolution, and the reference resolution the UI was originally designed with. This effect is not possible due to this engine bug it seems.

Reproduction:
Rep.rbxl (21.4 KB)

This is hindering my UI work, as I’m unable to create fluent UI based on the user’s resolution.

3 Likes

I’m not sure if I completly understand what you mean but you should click on textscaled to make sure the text don’t go out of the bounds.

I don’t want to use TextScaled, and shouldn’t need to be used with a UIScale. The UI was originally designed with a UIScale, so when it scales up or down, the text should stay the same size and scale with the red area, however, this isn’t the case.

I’m not sure if UIScale is meant to do that. You should really use TextScaled it will fix your problem

I initially tried TextScaled as I thought it’d scale, as the name suggests, but it unfortunately enables wrapping too, which I do not want at all.

You can see from the reproduction place that it does try to scale, but something internally is stopping it from scaling linearly with the red area.

Due to this, I came up with the idea of me just editing the size of the red area to match the size the TextLabel is taking up, but due to TextBounds being inaccurate, I am unable to do so.

Your specific case is because that TextBounds gives you a downscaled size (the size of text after the UIScale is applied). While size is the one before scale. If you set the size to match the textbounds, the final size that textlabel thinks it will apply to the text is the size you set * UIScale which causes the always overflow in your repro. to make this clearer, you could try create a frame under another gui without UIScale and assign the textbounds to its size, it matches the current text bounds.

And for your use case, I think you don’t need to do anything to make it auto fit but just use the UIScale to control everything, it will scale text correctly for you.

Ah, I see. I wanted to use the TextBounds so I could account for the text “snapping” by changing the side of the red background, as the text is not smoothly scaling, but it looks like this is not possible due to the reason you stated.

Currently it just looks like this when I use a UIScale with the dynamic scaling code: https://gyazo.com/eddd100aa3b98ad46c414a33832623a5 Is there any way I could stop this “snapping” without using TextWrapped?

It might be a bit hard, as our text size is not smooth, which means we could not have a 13.1246 size text. So when scaling we could only pick one existing size that makes most sense for this situation, and that might cause this issue.
But according to some professional industry designs, UI is sometimes designed in this way:
resolution between(res1, res2) the text size will be textSize1and prompt size is promptSize1 and stay fixed in this range. It does not always proportionally scale with resolution.
we are also trying to get a better solution with snapping.

1 Like

The text size property isn’t actually being set to a decimal number though. The size doesn’t change at all. All the UIScale should be doing is multiplying everything by a scale factor, which should give the effect that it is scaling linearly.

As for the TextBounds - it doesn’t actually give me a down scaled size at all. The property only changes on game launch, and then doesn’t change at all after that. I cannot understand as to why it’d only update on game launch and not whilst scaling.

Internally as those gui objects are not rendered onto a render target(like a canvas), so when scale them down we are applying scale on those objects individually.
About the second scenario, I tried to change UIScale at run time, the textbounds and absolutesize get changed accordingly to the UIScale.

I came up with the idea to print the X value of the TextBounds property of the TextLabel, and it does in fact update like you said. There is an issue with the properties menu however in Studio which make me believe that it wasn’t updating in the first place.

https://gyazo.com/9dcd7daf6aa18e75b787cd8e815c8522
Console = Real TextLabel TextBounds X Value
Studio Properties TextBounds = Staying the same

1 Like