I have a GUI that will contain usernames that I want to fit exactly around the username.
I was wondering if there was any way to do this other than
while not button.TextFits do
button.Size = button.Size + UDim2.new(0, 1, 0, 0)
end
I have a GUI that will contain usernames that I want to fit exactly around the username.
I was wondering if there was any way to do this other than
while not button.TextFits do
button.Size = button.Size + UDim2.new(0, 1, 0, 0)
end
You can use the TextService which contains the function GetTextSize that allows you to calculate the size of a frame needed for the inputted test along with its font and size.
A small example:-
local textServ = game:GetService('TextService')
local button = [some path to the button]
local newSize = textServ:GetTextSize(button.Text, button.TextSize, button.Font, button.AbsoluteSize) -- passes back a Vector2
-- set new button size
button.Size = Udim2.new(0, newSize.X, 0, newSize.Y)
I hope this helps.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
You can edit the CoreGui
What do you mean?
There isn't an easy way to "shrinkwrap" the size of the gui to fit the text in it. You can try a script that uses http://wiki.roblox.com/index.php?title=API:Class/TextService/GetTextSize to get the size of the text ahead of time, though this will mean that you will have to resize the gui yourself via script.
I believe I found a solution. http://wiki.roblox.com/index.php?title=API:Class/TextLabel/TextBounds TextBounds property is supposed to have a Vector2 for the size of the text