cLib.DTabPanel

VGUI - Containers Updated: Dec 10, 2025

cLib.DTabPanel

Modern tab panel with animated indicator.

Basic Usage

local tabs = vgui.Create("cLib.DTabPanel", parent)
tabs:Dock(FILL)

-- Add tabs (returns tab button and content panel)
local tab1, panel1 = tabs:AddTabPanel("Home", "icon16/house.png")
local tab2, panel2 = tabs:AddTabPanel("Settings", "icon16/cog.png")

-- Add content to panels
local label = vgui.Create("DLabel", panel1)
label:SetText("Home content here")
label:Dock(TOP)

Methods

MethodDescription
AddTab(title, icon, panel)Add existing panel as tab
AddTabPanel(title, icon)Create new panel and add as tab
SetActiveTab(tab)Set active tab
SetActiveTabByIndex(index)Set active by index
GetActiveTab()Get active tab button
GetActiveTabIndex()Get active tab index

Callbacks

tabs.OnTabChanged = function(self, index, title)
    print("Switched to tab:", index, title)
end

Styling

local tabs = vgui.Create("cLib.DTabPanel", parent)
tabs:SetBackgroundColor(Color(40, 40, 45))
tabs:SetTabColor(Color(50, 50, 55))
tabs:SetActiveTabColor(Color(60, 60, 65))
tabs:SetAccentColor(cLib.GetColor("cLib.accent"))  -- Indicator color

Complete Example

function CreateDashboard(parent)
    local tabs = vgui.Create("cLib.DTabPanel", parent)
    tabs:Dock(FILL)
    tabs:DockMargin(cLib.Scale(10), cLib.Scale(10), cLib.Scale(10), cLib.Scale(10))
    
    -- Overview tab
    local _, overview = tabs:AddTabPanel("Overview", "icon16/chart_pie.png")
    
    local stats = vgui.Create("DLabel", overview)
    stats:SetText("Statistics will appear here")
    stats:SetFont("cLib.Title")
    stats:Dock(TOP)
    stats:DockMargin(0, cLib.Scale(20), 0, 0)
    stats:SetContentAlignment(5)
    
    -- Players tab
    local _, players = tabs:AddTabPanel("Players", "icon16/group.png")
    
    local playerList = vgui.Create("cLib.DListView", players)
    playerList:Dock(FILL)
    playerList:AddColumn("Name")
    playerList:AddColumn("Score")
    playerList:AddColumn("Ping")
    
    -- Settings tab
    local _, settings = tabs:AddTabPanel("Settings", "icon16/cog.png")
    
    local setting1 = vgui.Create("cLib.DToggleLabel", settings)
    setting1:SetText("Enable feature")
    setting1:Dock(TOP)
    setting1:DockMargin(0, cLib.Scale(10), 0, 0)
    
    -- Tab change handler
    tabs.OnTabChanged = function(self, index, title)
        if title == "Players" then
            RefreshPlayerList(playerList)
        end
    end
    
    return tabs
end