Garry's Mod Wiki

Revision Difference

DCollapsibleCategory#526598

<panel> <parent>Panel</parent> <description> The collapsible category allows you to create numerous sections of controls, and have the ability to contract/expand them. Consider using <page>DCategoryList</page> if you plan on using more than 1 of these. </description> </panel> <example> <description>Creates a DCollapsibleCategory panel.</description> <code> local frame = vgui.Create( "DFrame" ) frame:SetSize( 300, 300 ) frame:Center() frame:MakePopup() local DCollapsible = vgui.Create( "DCollapsibleCategory", frame ) // Create a collapsible category DCollapsible:SetPos( 25, 50 ) // Set position⤶ DCollapsible:SetSize( 250, 100 ) // Set size⤶ DCollapsible:SetExpanded( 0 ) // Is it expanded when you open the panel?⤶ DCollapsible:SetLabel( "Collapsible Category" ) // Set the name ( label )⤶ local DermaList = vgui.Create( "DPanelList", DermaPanel ) // Make a list of items to add to our category ( collection of controls ) DermaList:SetSpacing( 5 ) // Set the spacing between items DermaList:EnableHorizontal( false ) // Only vertical items DermaList:EnableVerticalScrollbar( true ) // Enable the scrollbar if ( the contents are too wide⤶ DCollapsible:SetContents(DermaList) // Add DPanelList to our Collapsible Category local CategoryContentOne = vgui.Create( "DCheckBoxLabel" ) // This section creates a checkbox and CategoryContentOne:SetText( "God mode" ) // sets up its settings local DCollapsible = vgui.Create( "DCollapsibleCategory", frame ) -- Create a collapsible category DCollapsible:SetLabel( "Collapsible Category" ) -- Set the name ( label )⤶ DCollapsible:SetPos( 25, 50 ) -- Set position⤶ DCollapsible:SetSize( 250, 100 ) -- Set size⤶ DCollapsible:SetExpanded( false ) -- Start collapsed⤶ local DermaList = vgui.Create( "DPanelList", DermaPanel ) -- Make a list of items to add to our category (collection of controls) DermaList:SetSpacing( 5 ) -- Set the spacing between items DermaList:EnableHorizontal( false ) -- Only vertical items DermaList:EnableVerticalScrollbar( true ) -- Enable the scrollbar if (the contents are too wide)⤶ DCollapsible:SetContents( DermaList ) -- Add DPanelList to our Collapsible Category local CategoryContentOne = vgui.Create( "DCheckBoxLabel" ) -- This section creates a checkbox and CategoryContentOne:SetText( "God mode" ) -- sets up its settings CategoryContentOne:SetConVar( "sbox_godmode" ) CategoryContentOne:SetValue( 0 ) CategoryContentOne:SizeToContents() DermaList:AddItem( CategoryContentOne ) // Add the checkbox to the category local CategoryContentTwo = vgui.Create( "DLabel" ) // Make some more content DermaList:AddItem( CategoryContentOne ) -- Add the checkbox to the category local CategoryContentTwo = vgui.Create( "DLabel" ) -- Make some more content CategoryContentTwo:SetText( "Hello" ) DermaList:AddItem( CategoryContentTwo ) // Add it to the categoryDCollapsible:SetContents( DermaList ) // Set the contents of the category to the list DermaList:AddItem( CategoryContentTwo ) -- Add it to the categoryDCollapsible:SetContents( DermaList ) -- Set the contents of the category to the list </code> <output> <image src="DCollapsibleCategoryContracted.png" alt="Not_opened"/> <image src="DCollapsibleCategoryExpanded.png" alt="Opened"/> </output> </example>