Have you tried TextSizeConstraint?
That only sets the min and maximum size, it won’t help with what I need I believe
so if I can’t find a solution I will probably just have to keep all the text in one image label instead of separate ones
Using the constraint keeps the text sizes constant if you were to make the Min Size and Max Size the same
You could use the offset values under size of the TextLabels
Using the same text size just keeps it like text scaled disabled
and what do you mean by using the offset values?
For the size of the UI object could just use the Offset values instead of Scale
I need the text to grow though, I don’t want text to be too small on bigger screens, and to be way too large on mobile
Does using a text size constraint as well as enabling TextScaled help at all? Not sure if you’ve tried that yet.
I’ve already did that, it wont work as text size constraint limits how big text can get and TextScaled makes the text bigger so the limit stops it from growing
Could you try to make use of the size of the screen (using AbsoluteSize) of the whole window and use a formula to change the font size accordingly?
Possibly but that’s rather complicated for a couple of textlabels
Are you using Scale or Offset for the TextLabel sizes?
Is the TextScaled property enabled?
These could very well be both factors into why the text is scaling or not.
Because when testing Guis similar to the Gifs provided in the OP. The text scales for me without problem.
- Scale
- Yes
the text scaling is not the problem, I need them to keep the same text size as they grow so no text label’s text is bigger than the others
this is with text size cons and scaled enabled, the text does not grow
decided to just use the same text label as I do not believe there is an easy solution
I’m happy with it, turned out better than I thought it would
Could also just use multiple text labels. That would solve it.
That’s what I was doing, and that was the issue
Layer it up with text labels over frames. Should work if you size them individually. Might work if sized all together.
So you need them to keep the same text size so no text label’s text is bigger then the other’s. You could set the text size manually via the properties. Or you could utilize UITextSizeConstraint. Which based on a previous reply by you. You stated you believe it would not help with what you need.
While it does set the min and max Text-Size when the Gui scales. It should very well help in your problem of keeping the text the same size.
I didn’t mention it in the OP but the text would be changing so it would resize with text scaled enabled and thus the text not matching in sizes
I’m aware this is an old post, however, I have coded a solution for this problem. You can use the following 2 functions to solve your issue:
local DefaultTextSize = 90
local function CalculateSuitableTextSize(mainObject)
-- Set max size to default text size
local maxSize = DefaultTextSize
-- Loop through each object
for _, object in pairs(mainObject:GetDescendants()) do
-- Return if not text label
if not object:IsA("TextLabel") then continue end
local textLabel: TextLabel = object
local textBounds = textLabel.TextBounds
local absoluteSize = textLabel.AbsoluteSize
-- If text fits in box, then continue. TextFits property can be used here as an alternative
if textBounds.X < absoluteSize.X then continue end
-- If does not fit, then calculate text max size
local percentageToShrink = absoluteSize.X / textBounds.X
local newTextSize = textLabel.TextSize * percentageToShrink
-- Set new max text size
if newTextSize > maxSize then continue end
maxSize = newTextSize
end
return maxSize
end
local function SetTextSizeForAllTextLabels(mainObject, textSize)
for _, object in pairs(mainObject:GetDescendants()) do
if not object:IsA("TextLabel") then continue end
local textLabel: TextLabel = object
textLabel.TextSize = textSize
end
end
mainObject can be anything, however, should have all the text labels you want to be the same size. The “CalculateSuitableTextSize” function returns the size that all text labels can fit in.
Then you can the “SetTextSizeForAllTextLabels” with the text size that the previous functions returned. This will set all the text labels to the same size
Here’s the logic behind the maths:
Let’s say the following are the properties of the text label:
- AbsoluteSize.X = 50
- TextBounds.X = 100
- TextSize = 90
This means that the text takes up 100 pixels, but the text label can only fit 50. So you need to work out the percentage of how much you need to shrink the text bound box. To do this, you do:
- AbsoluteSize.X / TextBounds.X = PercentageToShrink
- Answer: 50 / 100 = 0.5
Then you apply that percentage decrease to the text size:
- TextSize * PercentageToShrink = NewTextSize
- 90 * 0.5 = 45
Finally, you check if the NewTextSize is smaller than the current SmallestTextSize. If it is, then set SmallestTextSize to equal NewTextSize. Example:
- SmallestTextSize = 50
- NewTextSize = 45
- Since 45 is smaller than 50, then set SmallestTextSize to 45
NOTE:
- This code only checks the X axis, however, feel free to adjust it to your needs.
- Text Scaled needs to be disabled, however, you can set the default text size to max size and these 2 functions should scale the text down
- To automatically scale the GUI when screen size changes, you’ll need to call these 2 functions whenever GUI.Changed event is called. If this does not work, you can also try RunService.Heartbeat
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.