Wrapping text with 'draw.DrawText'

Is it possible to wrap the text automatically to fit the boundaries of the current item?

Code Snippet:

local TestingPanel = vgui.Create( “DPanel”, ChangeTeamSheet )
TestingPanel:SetPos( ScrW()*0.11, ScrH()*0.01 )
TestingPanel:SetSize( ScrW()*0.62, ScrH()*0.21 )
TestingPanel.Paint = function() – Paint function
–Set our rect color below us; we do this so you can see items added to this panel
draw.RoundedBox( 8, 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall(), Color(50, 50, 50, 255) ) – Draw the rect
draw.DrawText("Description: "… TeamDescription[ply:Team()], “LargeFont”, TestingPanel:GetWide()*0.01, TestingPanel:GetTall()*0.05, Color(255, 255, 255, 255),TEXT_ALIGN_LEFT)

Unfortunately, I believe this wouldn’t work without you manually adding newlines to the string that will be printed. Last I checked, draw.DrawText() doesn’t really have overflow detection and I think it just cuts off the remaining letters that don’t fit into its width and height parameters.

You could, however:

  1. string.format() that string you’re printing
  2. Run it through a function that takes the width and height of the panel into consideration along with your personal calculation of how many words can safely fit on each line
  3. The function returns your string with appropriate newlines after the max amount of words that can fit on the line are reached throughout the whole string.

There may be an issue if the panel is resizeable, but there’s always a calculation or else we wouldn’t have properly-functioning text panels.

Okay, thanks for your help but I managed to get it working in the end.

If anyone want’s the completed testing and working code, here it is:

surface.CreateFont( “Ariel”, 48, 500, true, true, “LargeFont” )
surface.CreateFont( “Ariel”, 24, 500, true, true, “MediumFont” )
surface.CreateFont( “Ariel”, 16, 500, true, true, “SmallFont” )

UText = {}

function UpdateText(t)
	for i=1,4 do
		UText* = vgui.Create("DTextEntry", TestingPanel*)
		UText*:SetSize(TestingPanel*:GetWide() - 10, TestingPanel*:GetTall() - 10)
		if i == 1 then
			if t == 0 then
				UText*:SetText("Job Title: ".. team.GetName(t) .. "

Salary: "… TeamSalary[t] )
UText*:SetText("Job Title: “… team.GetName(t) … "
Salary: $”… TeamSalary[t] )
elseif i == 2 then
"… TeamDescription[t])
elseif i == 3 then
"… TeamRules[t])
elseif i == 4 then
UText*:SetText("Extra Information:
" … TeamExtraInfo[t])
hook.Add(“TextUpdate”, “Update the text!”, UpdateText)

hook.Call("TextUpdate", GAMEMODE, LocalPlayer():Team())