cLib.DScrollPanel
Scrollable container panel with styled scrollbar.
Basic Usage
local scroll = vgui.Create("cLib.DScrollPanel", parent)
scroll:Dock(FILL)
-- Add content
for i = 1, 50 do
local item = scroll:Add("DLabel")
item:SetText("Item " .. i)
item:Dock(TOP)
item:SetTall(cLib.Scale(30))
endMethods
| Method | Description |
|---|---|
Add(panelClass) | Add child panel |
AddItem(panel) | Add existing panel |
Clear() | Remove all children |
ScrollToChild(panel) | Scroll to panel |
GetCanvas() | Get content panel |
Styled Scrollbar
The scrollbar is automatically styled to match cLib theme.
local scroll = vgui.Create("cLib.DScrollPanel", parent)
scroll:Dock(FILL)
-- Access scrollbar if needed
local vbar = scroll:GetVBar()
vbar:SetWide(cLib.Scale(8))Content with Padding
local scroll = vgui.Create("cLib.DScrollPanel", parent)
scroll:Dock(FILL)
scroll:DockPadding(cLib.Scale(10), cLib.Scale(10), cLib.Scale(10), cLib.Scale(10))
-- Content will have padding from edges
for i = 1, 20 do
local panel = scroll:Add("DPanel")
panel:Dock(TOP)
panel:SetTall(cLib.Scale(60))
panel:DockMargin(0, 0, 0, cLib.Scale(5))
endItem List Example
function CreateItemList(parent, items)
local scroll = vgui.Create("cLib.DScrollPanel", parent)
scroll:Dock(FILL)
for _, item in ipairs(items) do
local row = scroll:Add("DPanel")
row:Dock(TOP)
row:SetTall(cLib.Scale(50))
row:DockMargin(cLib.Scale(5), cLib.Scale(5), cLib.Scale(5), 0)
row.Paint = function(s, w, h)
draw.RoundedBox(4, 0, 0, w, h, Color(50, 50, 55))
end
local icon = vgui.Create("DImage", row)
icon:SetSize(cLib.Scale(40), cLib.Scale(40))
icon:Dock(LEFT)
icon:DockMargin(cLib.Scale(5), cLib.Scale(5), cLib.Scale(10), cLib.Scale(5))
icon:SetImage(item.icon)
local name = vgui.Create("DLabel", row)
name:SetText(item.name)
name:SetFont("cLib.SubTitle")
name:Dock(FILL)
name:SetContentAlignment(4)
local price = vgui.Create("DLabel", row)
price:SetText("$" .. item.price)
price:SetFont("cLib.Text")
price:Dock(RIGHT)
price:SetWide(cLib.Scale(80))
price:SetContentAlignment(6)
end
return scroll
end