TextLabels unwanted behaviour

Hi!

I’m trying to make a chat box that displays the NPC’s name in the top.
However, I ran into a visual issue with TextLabels and constraints.

The problem lies with the inclusion of a “space” character in the TextLabel.
Take a look at the examples below to see what I mean.

With space

Without space

image

Because I included a space in the string itself, the TextLabel shifts the second word to a new line.
Is there a way to prevent this from happening?
I can provide more info if needed.

Thanks in advance!

1 Like

Do you have text wrapped on? If so, turn it off and see if that helps.

1 Like

That does help, but not exactly.

I’m trying to keep my text scaled based on screen size.
Disabling text wrapped will make the text appear as extremely small on very big screens,
which is what I want to avoid.

I’m confused on exactly what you mean by this.

1 Like

My text should be smaller on devices with smaller screens and vice versa.

With text wrapping

Without text wrapping

TextScaled should help with that I’m pretty sure.

1 Like

TextWrapped and TextScaled are both enabled in the two examples in the original post.
Disabling TextWrapped automatically disables TextScaled and disabling TextScaled but not TextWrapped will give the same result shown in the gif “Without text wrapping”.

Not entirely sure where the issue is?

1 Like

If you are also using a constraint to set limits on how big or small your text can be, and add a space inbetween a character, you will experience the same issue I’m having.

It’s also worth mentioning that even when I set the minimum text size on the constraint to 1, it will still show the same result from the original post.

Ah, I see now. I’m out of ideas. ;c

2 Likes

That’s alright. I appreciate the effort!

Make the textlabel longer.

With wrapping off it’ll make the text smaller so that it all fits on one line.

1 Like

Hi there!

I currently don’t believe it possible to scale text without wrapping using UI elements alone.
Here’s some code to achieve what you want :slightly_smiling_face: - If the width of the calculated text bounds exceeds the width of the textlabel size, the height is adjusted to fit in the box.
This was just done in a few minutes, so I’m sure you can avoid some of the calculations, such as removing one of the TextService:GetTextSize() calls altogether.

Partcline_AutoScaleTextNoWrap.rbxl (15 KB)

3 Likes

Thank you!!! This, with a few minor adjustments and paired with the constraint fixes the problem entirely!

The result

It’s still pretty annoying that we’re required to make separate code for something so simple.