--!strict local Tokenizer = require(script.Parent.Tokenizer) local Renderer = require(script.Parent.Renderer) local Bindings = require(script.Parent.Bindings) local Registry = require(script.Parent.Registry) local Sizing = require(script.Parent.Sizing) local Types = require(script.Parent.Types) local Lifecycle = {} local Methods = {} local Metatable = { __index = Methods } function Methods.Clear(self: Types.Helper) Bindings.Disconnect(self) for _, Child in self.Children do Child:Destroy() end table.clear(self.Children) table.clear(self.TextParts) table.clear(self.ImageParts) end function Methods.ApplyAlpha(self: Types.Helper) Bindings.ApplyAlpha(self) end function Methods.ApplyScaledSize(self: Types.Helper) Bindings.ApplyScaledSize(self) end function Methods.SetText(self: Types.Helper, Text: string) self.Version += 1 local CurrentVersion = self.Version self:Clear() local Label = self.Label local Segments = Tokenizer.Tokenize(Text) if not Tokenizer.ContainsImage(Segments) then Label.Text = Text Label.TextTransparency = 0 return end self.Scaled = Label.TextScaled self.BareText = Tokenizer.JoinText(Segments) local EffectiveSize = Label.TextSize if self.Scaled and Label.AbsoluteSize.Y > 0 then EffectiveSize = Sizing.Resolve(self.BareText, Label.FontFace, Label.AbsoluteSize) if self.Version ~= CurrentVersion then return end end Label.Text = "" local Parts = Renderer.Build(Label, Segments, EffectiveSize) self.Children = Parts.Children self.TextParts = Parts.TextParts self.ImageParts = Parts.ImageParts Bindings.Connect(self, CurrentVersion) end function Methods.Destroy(self: Types.Helper) self.Version += 1 self:Clear() self.Label.Text = "" self.Label.TextTransparency = 0 Registry.Release(self.Label, self) end function Lifecycle.New(Label: TextLabel): Types.Helper local Helper = { Label = Label, Children = {}, TextParts = {}, ImageParts = {}, BareText = "", Scaled = false, Connection = nil, AlphaConnection = nil, Version = 0, } return setmetatable(Helper, Metatable) :: any end return Lifecycle