Garry's Mod Wiki

DCollapsibleCategory

Description

The collapsible category allows you to create numerous sections of controls, and have the ability to contract/expand them.

Consider using DCategoryList if you plan on using more than 1 of these.

View source

Parent

Derives methods, etc not listed on this page from Panel.

Implements

Implements or overrides the following hooks/methods. If you want to override these, you probably want to call the original function too.

Events

DCollapsibleCategory:OnToggle( boolean expanded )
Called by DCollapsibleCategory:Toggle. This function does nothing by itself, as you're supposed to overwrite it.

Methods

Panel DCollapsibleCategory:Add( string name )
Adds a new text button to the collapsible category, like the tool menu in Spawnmenu.
DCollapsibleCategory:AnimSlide( table anim, number delta, table data )
Internal: This is used internally - although you're able to use it you probably shouldn't. Internal function that handles the open/close animations.
DCollapsibleCategory:DoExpansion( boolean expand )
Forces the category to open or collapse
number DCollapsibleCategory:GetAnimTime()
An AccessorFunc that returns the expand/collapse animation time set by DCollapsibleCategory:SetAnimTime.
boolean DCollapsibleCategory:GetDrawBackground()
Deprecated: We advise against using this. It may be changed or removed in a future update. You should use DCollapsibleCategory:GetPaintBackground instead. Returns whether or not the panel background is being drawn. Alias of DCollapsibleCategory:GetPaintBackground.
boolean DCollapsibleCategory:GetExpanded()
Returns whether the DCollapsibleCategory is expanded or not.
number DCollapsibleCategory:GetHeaderHeight()
Returns the header height of the DCollapsibleCategory. See also DCollapsibleCategory:SetHeaderHeight.
Panel DCollapsibleCategory:GetList()
If set, the DCategoryList that created this panel. See also DCollapsibleCategory:SetList.
number DCollapsibleCategory:GetPadding()
Deprecated: We advise against using this. It may be changed or removed in a future update. Doesn't actually do anything. Returns the number set by DCollapsibleCategory:SetPadding.
boolean DCollapsibleCategory:GetPaintBackground()
An AccessorFunc that returns whether or not the background should be painted.
number DCollapsibleCategory:GetStartHeight()
Deprecated: We advise against using this. It may be changed or removed in a future update. Returns whatever was set by DCollapsibleCategory:SetStartHeight
DCollapsibleCategory:SetAnimTime( number time )
Sets the time in seconds it takes to expand the DCollapsibleCategory
DCollapsibleCategory:SetContents( Panel pnl )
Sets the contents of the DCollapsibleCategory.
DCollapsibleCategory:SetDrawBackground( boolean draw )
Deprecated: We advise against using this. It may be changed or removed in a future update. You should use DCollapsibleCategory:SetPaintBackground instead. Sets whether or not to draw the panel background. Alias of DCollapsibleCategory:SetPaintBackground.
DCollapsibleCategory:SetExpanded( boolean expanded = true )
Sets whether the DCollapsibleCategory is expanded or not upon opening the container. You should use DCollapsibleCategory:Toggle or DCollapsibleCategory:DoExpansion instead.
DCollapsibleCategory:SetHeaderHeight( number height )
Sets the header height of the DCollapsibleCategory. See also DCollapsibleCategory:GetHeaderHeight.
DCollapsibleCategory:SetLabel( string label )
Sets the name of the DCollapsibleCategory.
DCollapsibleCategory:SetList( Panel pnl )
Used internally by DCategoryList when it creates a DCollapsibleCategory during DCategoryList:Add. If set, Panel:UnselectAll will be called on the list, instead of calling it on the category panel itself when a category is clicked.
DCollapsibleCategory:SetPadding( number padding )
Deprecated: We advise against using this. It may be changed or removed in a future update. Doesn't actually do anything.
DCollapsibleCategory:SetPaintBackground( boolean paint )
Sets whether or not the background should be painted.
DCollapsibleCategory:SetStartHeight( number height )
Deprecated: We advise against using this. It may be changed or removed in a future update. Does nothing.
DCollapsibleCategory:Toggle()
Toggles the expanded state of the DCollapsibleCategory. See DCollapsibleCategory:GetExpanded for a function to retrieve the expanded state.
DCollapsibleCategory:UpdateAltLines()
Internal: This is used internally - although you're able to use it you probably shouldn't. Used internally to update the "AltLine" property on all "child" panels.

Example

Creates a DCollapsibleCategory panel using a sub panel for its content.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 300, 300 ) frame:Center() frame:MakePopup() local DCollapsible = vgui.Create( "DCollapsibleCategory", frame ) -- Create a collapsible category DCollapsible:SetLabel( "My Collapsible Category" ) -- Set the name ( label ) DCollapsible:SetPos( 25, 50 ) -- Set position DCollapsible:SetSize( 250, 15 ) -- Set size DCollapsible:SetExpanded( false ) -- Collapsed by default local DermaList = vgui.Create( "DPanel" ) -- Make a list of items to add to our category (collection of controls) DermaList:DockPadding( 5, 5, 5, 5 ) -- Set padding for the list Derma_Hook( DermaList, "Paint", "Paint", "CategoryList" ) DCollapsible:SetContents( DermaList ) -- Add DPanelList to our Collapsible Category local myCheckbox = vgui.Create( "DCheckBoxLabel", DermaList ) -- This section creates a checkbox and myCheckbox:SetText( "God mode" ) -- sets up its settings myCheckbox:SetConVar( "sbox_godmode" ) myCheckbox:SetValue( false ) myCheckbox:SetDark( true ) myCheckbox:Dock( TOP ) local myLabel = vgui.Create( "DLabel", DermaList ) -- Make some more content myLabel:SetText( "Hello" ) myLabel:SetDark( true ) myLabel:Dock( TOP )
Output:
March03-2389-gmod.gif

Example

Creates a DCollapsibleCategory of simple selectable text options, exactly like the toolgun section of the spawnmenu.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 300, 300 ) frame:Center() frame:MakePopup() local DermaList = vgui.Create( "DPanel", frame ) DermaList:Dock( FILL ) Derma_Hook( DermaList, "Paint", "Paint", "CategoryList" ) -- Use the background from DCategoryList panel (via the derma skin system) local DCollapsible = vgui.Create( "DCollapsibleCategory", DermaList ) DCollapsible:SetLabel( "Collapsible List" ) DCollapsible:Dock( TOP ) local btn = DCollapsible:Add( "Option one" ) btn.DoClick = function() Derma_Message("Clicked option one", "Info", "OK") end DCollapsible:Add( "Option 2" ) DCollapsible:Add( "Option III" )
Output:
March03-2392-gmod.gif