cLib.DCategoryList

VGUI - Containers Updated: Dec 10, 2025

cLib.DCategoryList

Collapsible category list for organized item displays.

Basic Usage

local catList = vgui.Create("cLib.DCategoryList", parent)
catList:Dock(FILL)

local cat1 = catList:AddCategory("Weapons")
local cat2 = catList:AddCategory("Tools")

-- Add items to categories
local item = cat1:Add("cLib.DButton")
item:SetText("AK-47")
item:Dock(TOP)

Methods

DCategoryList

MethodDescription
AddCategory(name)Add new category
GetCategories()Get all categories
Clear()Remove all categories

Category

MethodDescription
Add(panelClass)Add item to category
SetLabel(string)Set category name
SetExpanded(bool)Expand/collapse
Toggle()Toggle expanded
Clear()Remove all items

Shop Category Example

function CreateShopCategories(parent)
    local catList = vgui.Create("cLib.DCategoryList", parent)
    catList:Dock(FILL)
    
    local categories = {
        {
            name = "Weapons",
            items = {
                {name = "Pistol", price = 100, icon = "icon16/gun.png"},
                {name = "Rifle", price = 500, icon = "icon16/gun.png"},
                {name = "Shotgun", price = 350, icon = "icon16/gun.png"}
            }
        },
        {
            name = "Armor",
            items = {
                {name = "Light Vest", price = 200, icon = "icon16/shield.png"},
                {name = "Heavy Vest", price = 400, icon = "icon16/shield.png"}
            }
        },
        {
            name = "Utilities",
            items = {
                {name = "Medkit", price = 50, icon = "icon16/heart.png"},
                {name = "Flashlight", price = 25, icon = "icon16/lightbulb.png"}
            }
        }
    }
    
    for _, cat in ipairs(categories) do
        local category = catList:AddCategory(cat.name)
        
        for _, item in ipairs(cat.items) do
            local btn = category:Add("DPanel")
            btn:Dock(TOP)
            btn:SetTall(cLib.Scale(40))
            btn:DockMargin(0, 0, 0, 1)
            
            btn.Paint = function(s, w, h)
                local col = s:IsHovered() and Color(60, 60, 65) or Color(50, 50, 55)
                draw.RoundedBox(0, 0, 0, w, h, col)
            end
            
            btn.OnMousePressed = function(s)
                BuyItem(item.name)
            end
            
            local icon = vgui.Create("DImage", btn)
            icon:SetSize(cLib.Scale(24), cLib.Scale(24))
            icon:SetImage(item.icon)
            icon:Dock(LEFT)
            icon:DockMargin(cLib.Scale(8), cLib.Scale(8), cLib.Scale(8), cLib.Scale(8))
            
            local name = vgui.Create("DLabel", btn)
            name:SetText(item.name)
            name:Dock(FILL)
            name:SetContentAlignment(4)
            
            local price = vgui.Create("DLabel", btn)
            price:SetText("$" .. item.price)
            price:Dock(RIGHT)
            price:SetWide(cLib.Scale(60))
            price:SetContentAlignment(6)
            price:DockMargin(0, 0, cLib.Scale(10), 0)
        end
    end
    
    return catList
end