Array VGUI Items

I want to create DPanels for every value in RPExtraTeams table and also I need to array them like this;

http://puu.sh/ujHnJ/d4d6647ebc.png

I did this via this code;


local stp = stp or {}
local panelwid, paneltall = 375,200

local function fillStatistics()
	local line = 1
	local shouldnewline = false

	for k,v in pairs(RPExtraTeams) do
		if (table.Count(stp)<=1) then -- if there isn't any value in stp table then, create a panel for the first
			local panel = vgui.Create("DPanel", istatistikler)
			panel:SetSize(panelwid,paneltall)
			panel:SetPos(5,5)
			stp[k] = panel -- set the key of this panel in stp table to the team id defined in RPExtraTeams table
		else 
			local b = stp[k-1] -- get previous panel
			local bx, by = b:GetPos() -- get previous panel x, y

			if (((bx+b:GetWide()+5)+panelwid)>f:GetWide()-5) then -- if previous panel x position + previous panel wide + current panel wide > main scroll panel wide - 5 then (-5 for borders)
				line = line+1 -- we should be on second line
				shouldnewline = true
			end
			
			if (shouldnewline==true) then -- if current panel is the first value of the new line then
				shouldnewline = false -- it wont be the first after creating current panel so set it back to false
				local panel = vgui.Create("DPanel", istatistikler)
				panel:SetSize(panelwid,paneltall)
				panel:SetPos(5,((line-1)*paneltall)+line*5)
				stp[k] = panel -- set the key of this panel in stp table to the team id defined in RPExtraTeams table
			else 
				local panel = vgui.Create("DPanel", istatistikler)
				panel:SetSize(panelwid,paneltall)
				panel:SetPos(bx+b:GetWide()+5,by)
				stp[k] = panel -- set the key of this panel in stp table to the team id defined in RPExtraTeams table
			end	
		end
	end
end

It works perfectly but I don’t think it is the best way to do that. Do you guys have any suggestion to do that?

use

DIconLayout

Thank you. You saved my hours xD