
/*   _                                
    ( )                               
   _| |   __   _ __   ___ ___     _ _ 
 /'_` | /'__`\( '__)/' _ ` _ `\ /'_` )
( (_| |(  ___/| |   | ( ) ( ) |( (_| |
`\__,_)`\____)(_)   (_) (_) (_)`\__,_) 

	DPropertySheet

*/

local PANEL = {}

AccessorFunc( PANEL, "ActiveButton", 			"ActiveButton" )

/*---------------------------------------------------------
   Name: Init
---------------------------------------------------------*/
function PANEL:Init()
	
	self.Navigation 	= vgui.Create( "DScrollPanel", self )
	self.Navigation:Dock( LEFT )
	self.Navigation:SetWidth( 100 )
	self.Navigation:DockMargin( 10, 10, 10, 0 )
	
	self.Content 	= vgui.Create( "DPanel", self )
	self.Content:Dock( FILL )
	self.Content:SetBackgroundColor( Color( 250, 250, 250, 255 ) )
	self.Content:SetPaintBackground( true )

	self.Items = {}
	
end

/*---------------------------------------------------------
   Name: AddSheet
---------------------------------------------------------*/
function PANEL:AddSheet( label, panel, material )

	if ( !IsValid( panel ) ) then return end

	local Sheet = {}
	
	Sheet.Button = vgui.Create( "DButton", self.Navigation )
	Sheet.Button:SetImage( material )
	Sheet.Button.Target = panel
	Sheet.Button:Dock( TOP )
	Sheet.Button:SetText( label )
	Sheet.Button:DockMargin( 0, 1, 0, 0 )
	
	Sheet.Button.DoClick = function ()

		self:SetActiveButton( Sheet.Button )
	
		end
	
	Sheet.Panel = panel
	Sheet.Panel:SetParent( self.Content )
	Sheet.Panel:SetVisible( false )
	
	table.insert( self.Items, Sheet )
	
	if ( !IsValid( self.ActiveButton ) ) then
		self:SetActiveButton( Sheet.Button )
	end

end

/*---------------------------------------------------------
   Name: SetActiveTab
---------------------------------------------------------*/
function PANEL:SetActiveButton( active )

	if ( self.ActiveButton == active ) then return end
	
	if ( self.ActiveButton && self.ActiveButton.Target ) then	
		self.ActiveButton.Target:SetVisible( false )
		self.ActiveButton:SetSelected( false )
	end

	self.ActiveButton = active
	active.Target:SetVisible( true )
	active:SetSelected( true )
	
	self.Content:InvalidateLayout()

end

derma.DefineControl( "DColumnSheet", "", PANEL, "Panel" )
