--!strict local Constants = require(script.Parent.Constants) local Tokenizer = require(script.Parent.Tokenizer) local Types = require(script.Parent.Types) local Renderer = {} local function CreateLayout(Label: TextLabel): UIListLayout local Layout = Instance.new("UIListLayout") Layout.FillDirection = Enum.FillDirection.Horizontal Layout.SortOrder = Enum.SortOrder.LayoutOrder Layout.VerticalAlignment = Enum.VerticalAlignment.Center Layout.HorizontalAlignment = Constants.Alignments[Label.TextXAlignment] or Enum.HorizontalAlignment.Center Layout.Padding = Constants.LayoutPadding Layout.Parent = Label return Layout end local function CreateTextPart(Label: TextLabel, Value: string, Order: number, Size: number, Stroke: UIStroke?): TextLabel local Part = Instance.new("TextLabel") Part.BackgroundTransparency = 1 Part.AutomaticSize = Enum.AutomaticSize.X Part.Size = UDim2.fromScale(0, 1) Part.LayoutOrder = Order Part.Text = Value Part.RichText = Label.RichText Part.FontFace = Label.FontFace Part.TextScaled = false Part.TextSize = Size Part.TextColor3 = Label.TextColor3 Part.TextTransparency = 0 Part.TextWrapped = false Part.TextXAlignment = Enum.TextXAlignment.Center if Stroke then Stroke:Clone().Parent = Part end Part.Parent = Label return Part end local function CreateImagePart(Label: TextLabel, AssetId: string, Order: number): ImageLabel local Image = Instance.new("ImageLabel") Image.BackgroundTransparency = 1 Image.Image = AssetId Image.Size = UDim2.fromScale(1, 1) Image.SizeConstraint = Enum.SizeConstraint.RelativeYY Image.LayoutOrder = Order local Aspect = Instance.new("UIAspectRatioConstraint") Aspect.AspectRatio = 1 Aspect.Parent = Image Image.Parent = Label return Image end function Renderer.Build(Label: TextLabel, Segments: { Types.Segment }, Size: number): Types.Parts local Parts: Types.Parts = { Children = {}, TextParts = {}, ImageParts = {} } local Stroke = Label:FindFirstChildOfClass("UIStroke") table.insert(Parts.Children, CreateLayout(Label)) for Order, Segment in Segments do if Segment.Kind == "Text" then local Part = CreateTextPart(Label, Segment.Value, Order, Size, Stroke) table.insert(Parts.Children, Part) table.insert(Parts.TextParts, Part) continue end local AssetId = Tokenizer.ResolveImage(Segment.Value) if AssetId then local Image = CreateImagePart(Label, AssetId, Order) table.insert(Parts.Children, Image) table.insert(Parts.ImageParts, Image) end end return Parts end return Renderer