cLib.DAccordion
Collapsible accordion with multiple sections.
Basic Usage
local accordion = vgui.Create("cLib.DAccordion", parent)
accordion:Dock(FILL)
local section1 = accordion:AddSection("General", "icon16/cog.png")
local section2 = accordion:AddSection("Advanced", "icon16/wrench.png")
-- Add content to sections
local content = section1:GetContent()
local label = vgui.Create("DLabel", content)
label:SetText("Content here")
label:Dock(TOP)
Methods
DAccordion
| Method | Description |
|---|
AddSection(title, icon) | Add new section |
CollapseAll(except) | Collapse all sections |
SetAllowMultiple(bool) | Allow multiple open |
DAccordionSection
| Method | Description |
|---|
SetTitle(string) | Section title |
SetIcon(path) | Section icon |
SetExpanded(bool) | Expand/collapse |
Toggle() | Toggle expanded |
GetContent() | Get content panel |
SetContentHeight(number) | Set content height |
Allow Multiple Open
local accordion = vgui.Create("cLib.DAccordion", parent)
accordion:SetAllowMultiple(true) -- Multiple sections can be open
-- When false (default), opening one closes others
FAQ Example
function CreateFAQ(parent)
local accordion = vgui.Create("cLib.DAccordion", parent)
accordion:Dock(FILL)
accordion:SetAllowMultiple(true)
local faqs = {
{
q = "How do I get started?",
a = "Simply download the addon and place it in your addons folder."
},
{
q = "How do I configure settings?",
a = "Open the menu with F4 and navigate to the Settings tab."
},
{
q = "Can I customize colors?",
a = "Yes! All colors can be customized in the config file."
}
}
for i, faq in ipairs(faqs) do
local section = accordion:AddSection(faq.q, "icon16/help.png")
section:SetContentHeight(cLib.Scale(80))
local content = section:GetContent()
local answer = vgui.Create("DLabel", content)
answer:SetText(faq.a)
answer:SetWrap(true)
answer:SetAutoStretchVertical(true)
answer:Dock(FILL)
answer:DockMargin(cLib.Scale(10), cLib.Scale(10), cLib.Scale(10), cLib.Scale(10))
end
return accordion
end
Settings Sections
function CreateCategorizedSettings(parent)
local accordion = vgui.Create("cLib.DAccordion", parent)
accordion:Dock(FILL)
-- Display section
local display = accordion:AddSection("Display", "icon16/monitor.png")
display:SetContentHeight(cLib.Scale(150))
display:SetExpanded(true) -- Open by default
local displayContent = display:GetContent()
-- Add display settings...
-- Audio section
local audio = accordion:AddSection("Audio", "icon16/sound.png")
audio:SetContentHeight(cLib.Scale(120))
local audioContent = audio:GetContent()
-- Add audio settings...
-- Controls section
local controls = accordion:AddSection("Controls", "icon16/keyboard.png")
controls:SetContentHeight(cLib.Scale(200))
local controlsContent = controls:GetContent()
-- Add control bindings...
return accordion
end