Garry's Mod Wiki


  number Panel:GetNumLines()


Returns the number of lines in a RichText or a TextEntry.

You must wait a couple frames before calling this after using Panel:AppendText or Panel:SetText, otherwise it will return the number of text lines before the text change.


1 number
The number of lines.


Creates a rich text panel with a block of text and prints out the number of text lines before and after PerformLayout is called.

-- Create a window frame TextFrame = vgui.Create("DFrame") TextFrame:SetSize(200, 224) TextFrame:Center() TextFrame:SetTitle("Generic Frame") -- RichText panel local richtext = vgui.Create("RichText", TextFrame) richtext:Dock(FILL) -- Throw some text in the panel richtext:SetText("This is a block of text demonstrating how line wrapping and panel size relates to the number of lines shown inside of a RichText panel.") -- Keep track of PerformLayout calls richtext.layoutCount = 0 -- Custom function for this example function richtext:NumLinesExample() print("PerformLayout called "..self.layoutCount.." times: "..richtext:GetNumLines().." line(s) returned") end -- Print # of lines before any layouts richtext:NumLinesExample() -- Render update function richtext:PerformLayout() self.layoutCount = self.layoutCount + 1 self:NumLinesExample() -- Print current # of lines end
Output: The panel shows 5 lines of text, but the number 5 isn't returned until PerformLayout has been called 2 times.
PerformLayout called 0 times: 1 line(s) returned PerformLayout called 1 times: 1 line(s) returned PerformLayout called 2 times: 5 line(s) returned