cLib.DComboBox
Dropdown selection menu.
Basic Usage
local combo = vgui.Create("cLib.DComboBox", parent)
combo:SetSize(cLib.Scale(200), cLib.Scale(30))
combo:AddChoice("Option 1", "value1")
combo:AddChoice("Option 2", "value2")
combo:AddChoice("Option 3", "value3")
combo.OnSelect = function(self, index, value, data)
print("Selected:", value, "Data:", data)
endMethods
| Method | Description |
|---|---|
AddChoice(text, data, select, icon) | Add option |
SetValue(string) | Set selected text |
GetValue() | Get selected text |
GetSelected() | Get text and data |
GetSelectedID() | Get selected index |
SetPlaceholder(string) | Placeholder text |
Clear() | Remove all choices |
ChooseOption(text, index) | Select by text/index |
With Data Values
local teamSelect = vgui.Create("cLib.DComboBox", parent)
teamSelect:SetPlaceholder("Select Team...")
-- text, data, selected, icon
teamSelect:AddChoice("Red Team", TEAM_RED, false, "icon16/flag_red.png")
teamSelect:AddChoice("Blue Team", TEAM_BLUE, false, "icon16/flag_blue.png")
teamSelect:AddChoice("Spectator", TEAM_SPECTATOR, false, "icon16/eye.png")
teamSelect.OnSelect = function(self, index, text, teamID)
RunConsoleCommand("changeteam", teamID)
endDynamic Options
local playerSelect = vgui.Create("cLib.DComboBox", parent)
playerSelect:SetPlaceholder("Select Player...")
-- Populate with current players
for _, ply in ipairs(player.GetAll()) do
playerSelect:AddChoice(ply:Nick(), ply:SteamID64())
end
-- Refresh function
function playerSelect:Refresh()
self:Clear()
self:SetPlaceholder("Select Player...")
for _, ply in ipairs(player.GetAll()) do
self:AddChoice(ply:Nick(), ply:SteamID64())
end
endPre-select Value
local combo = vgui.Create("cLib.DComboBox", parent)
combo:AddChoice("Easy", 1)
combo:AddChoice("Normal", 2, true) -- Selected by default
combo:AddChoice("Hard", 3)
-- Or set after
combo:ChooseOption("Normal", 2)Styling
local combo = vgui.Create("cLib.DComboBox", parent)
combo:SetBackgroundColor(Color(50, 50, 55))
combo:SetTextColor(Color(220, 220, 220))
combo:SetArrowColor(Color(150, 150, 150))