

local PANEL = {}

/*---------------------------------------------------------
   Name: Init
---------------------------------------------------------*/
function PANEL:Init()

	self.List = vgui.Create( "DPanelList", self )
		self.List:EnableHorizontal( false )
		self.List:EnableVerticalScrollbar()
		self.List:SetSpacing( 1 )
		self.List:SetPadding( 3 )
		
		self.List.BackgroundColor = NamedColor( "ControlInside" )
		
	self.Items = {}

end


/*---------------------------------------------------------
   Name: Think
---------------------------------------------------------*/
function PANEL:Think()
	
	// Perform Layout every frame if we're sliding
	if ( self.MovementEnd ) then
		if ( self.MovementEnd < RealTime() ) then self.MovementEnd = nil end
		self:PerformLayout()
	end


end

/*---------------------------------------------------------
   Name: Init
---------------------------------------------------------*/
function PANEL:Clear()

	self.List:Clear()
	self.Items = {}
end

/*---------------------------------------------------------
   Name: AddItem
---------------------------------------------------------*/
function PANEL:AddItem( toolpanel, iParent, name, label, command, controlpanel, full_table )

	local pItem = nil
	
	if ( !controlpanel ) then
	
		pItem = vgui.Create( "ToolTree_Group", self )
			pItem:Setup( toolpanel, iparent, name, label, command, controlpanel, self, full_table )
		
		self.List:AddItem( pItem )
	
	else

		pItem = vgui.Create( "ToolTree_Button", self )
			pItem:Setup( toolpanel, iparent, name, label, command, controlpanel, self, full_table, true )
			pItem.Num = #self.Items
		
		// If we don't have a group then
		// add directly to the panel list
		if ( iParent == -1 ) then
			self.List:AddItem( pItem )
			
		// Else add it directly to our group
		else
		
			local Group = self.Items[ iParent ]
				Group:AddItem( pItem )
		
		end
	
	end
	
	//self.List:InvalidateLayout( true )	
	self:PerformLayout()	

	return table.insert( self.Items, pItem )

end


/*---------------------------------------------------------
   Name: PerformLayout
---------------------------------------------------------*/
function PANEL:PerformLayout()

	self.List:SetPos( 0, 0 )
	self.List:SetSize( self:GetWide(), self:GetTall() )
	
	self.List:PerformLayout()	
	
end

/*---------------------------------------------------------
   Name: PerformLayout
---------------------------------------------------------*/
function PANEL:SetAllExpanded( expand )

	for k, v in pairs( self.Items ) do
	
		if ( v.ToggleClosed ) then
		
			v.Closed = expand
			v:ToggleClosed()
		
		end
	
	end

end

/*---------------------------------------------------------
   Name: Paint
---------------------------------------------------------*/
function PANEL:Paint()

end

vgui.Register( "ToolTree_Tree", PANEL, "Panel" )