Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local testGui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
- local testLabel = Instance.new("TextLabel", testGui)
- testLabel.Position = UDim2.new(1,0,1,0)
- testLabel.Transparency = 1
- testLabel.TextWrapped = true
- local cache = {} --cache table is as follows: cache -> font -> fontSize -> frameSize -> text
- for _,font in next,Enum.Font:GetEnumItems() do
- local c = {}
- for _,fontSize in next,Enum.FontSize:GetEnumItems() do
- c[fontSize] = {}
- end
- cache[font] = c
- end
- local TextService = {}
- function TextService:GetTextSize(text, font, fontSize, frameSize)
- frameSize = frameSize or Vector2.new(0,0)
- local frameSizeString = tostring(frameSize)
- cache[font][fontSize][frameSizeString] = cache[font][fontSize][frameSizeString] or {}
- if not cache[font][fontSize][frameSizeString][text] then
- testLabel.Size = UDim2.new(0,frameSize.X,0,frameSize.Y)
- testLabel.Font = font
- testLabel.FontSize = fontSize
- testLabel.Text = text
- cache[font][fontSize][frameSizeString][text] = testLabel.TextBounds
- end
- return cache[font][fontSize][frameSizeString][text]
- end
- return TextService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement