Wrapping chat text

I have this piece of code in a function, it’s for a special chatbox. Anyways, the text cant clip of it’s parent, so when it gets too long it just dissapears.

[lua] local line = vgui.Create(“DLabel”);

	line:SetFont("Trebuchet18");
	line:SetTextColor( Color(0,0,0,255) );
	line:SetText( tbl ) -- Max width of a text line = self:GetWide() - 50
	line:SizeToContents();
	
	self.ChatLines:AddItem( line )[/lua]

What is the best way to make sure the text doesn’t get bigger then self:GetWide() - 50?

I was thinking of doing something like this:

  • Get how wide 1 character is
  • See how many characters fall off
  • string sub those characters and run the function again but now with the fallen off characters.

How would I do this?

Since you’re using DLabel: **[DLabel.SetWrap

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=DLabel.SetWrap)**

  • Fixed it myself -