Trying to make a little tip appear giving you some more information when hovering over parts in workspace. It works well, with the exception of the TextLabel looking, eh…
I know I read something about an upcoming feature on scaling TextLabels based on their text’s length, and I am not if it released or not.
And if it didn’t, what other alternatives could I use? Are there any known algorithms for calculating sizes like these? I was never able to make a proper one in the past. Font is Code so this should help very much.
You could use the TextScaled property which would automatically make it fit the max possible size for the textbox.
I know that’s a thing, but I’m looking into ways to scale the entire TextLabel relative to the text’s length. I think it would look way better this way. It’s still a last resort option though.
You could look into using UITextConstraint with textscaled and it should look better. If not then you can create a script for this.
function TextSize(Frame, Percent)
local Size = Frame.AbsoluteSize.Y * (Percent/100)
if Size > Frame.AbsoluteSize.X then
Size = Frame.AbsoluteSize.X * (Percent/100)
Managed to do an algorithm without any sort of help.
If anyone needs it:
local function calculateSize(String)
local Lines = math.ceil(string.len(String) / 30) -- / 30 should be replaced with the max characters on your line.
Tip.Size = UDim2.fromOffset(210, Lines * 14) -- * 14 should be replaced with however big you want a line to be
-- Also Replace Tip to whatever TextLabel you're changing the size of.
In general I only recommend fonts like Code, where all characters have equal width.
go to properties and edit AutomaticSize
I know this is an old post but I recently came across a new and easier way of doing this. You can use the TextBounds property to get the area of the text’s size of the textlabel in offsets. You can then resize the label using these offsets to have it so that the frame will only be as big as the text. No calculations needed.
If you would to read more into TextBounds or any other property, here is the documentation for the TextLabel : Link