cLib.DColorPicker

VGUI - Input Updated: Dec 10, 2025

cLib.DColorPicker

Color selection with HSV picker, hex input, and preview.

Basic Usage

local picker = vgui.Create("cLib.DColorPicker", parent)
picker:SetColor(Color(255, 100, 100))

picker.OnColorChanged = function(self, color)
    print("Selected:", color.r, color.g, color.b, color.a)
end

Methods

MethodDescription
SetColor(Color)Set current color
GetColor()Get current color

Components

The picker includes:

  • HSV color square (saturation/value)
  • Hue slider (rainbow)
  • Alpha slider (transparency)
  • Color preview
  • Hex input (#RRGGBB)
  • RGB/A number inputs

In Settings

local colorLabel = vgui.Create("DLabel", parent)
colorLabel:SetText("HUD Color:")
colorLabel:Dock(TOP)

local picker = vgui.Create("cLib.DColorPicker", parent)
picker:SetColor(GetHUDColor())
picker:Dock(TOP)
picker:DockMargin(0, cLib.Scale(5), 0, cLib.Scale(15))

picker.OnColorChanged = function(self, color)
    SetHUDColor(color)
    PreviewHUD()
end

Color Presets

local presets = {
    Color(255, 0, 0),    -- Red
    Color(0, 255, 0),    -- Green
    Color(0, 0, 255),    -- Blue
    Color(255, 255, 0),  -- Yellow
    Color(255, 0, 255),  -- Magenta
    Color(0, 255, 255),  -- Cyan
}

local presetPanel = vgui.Create("DPanel", parent)
presetPanel:Dock(TOP)
presetPanel:SetTall(cLib.Scale(30))
presetPanel.Paint = nil

for i, color in ipairs(presets) do
    local btn = vgui.Create("DButton", presetPanel)
    btn:SetSize(cLib.Scale(25), cLib.Scale(25))
    btn:SetPos((i-1) * cLib.Scale(30), 0)
    btn:SetText("")
    btn.Paint = function(s, w, h)
        draw.RoundedBox(4, 0, 0, w, h, color)
        if s:IsHovered() then
            surface.SetDrawColor(255, 255, 255, 100)
            surface.DrawOutlinedRect(0, 0, w, h, 2)
        end
    end
    btn.DoClick = function()
        picker:SetColor(color)
    end
end

Dialog Version

function OpenColorPicker(currentColor, callback)
    local frame = vgui.Create("cLib.DFrame")
    frame:SetSize(cLib.Scale(300), cLib.Scale(280))
    frame:SetTitle("Choose Color")
    frame:Center()
    frame:MakePopup()
    
    local picker = vgui.Create("cLib.DColorPicker", frame.mainContainer)
    picker:Dock(FILL)
    picker:DockMargin(cLib.Scale(10), cLib.Scale(10), cLib.Scale(10), cLib.Scale(50))
    picker:SetColor(currentColor or Color(255, 255, 255))
    
    local btnPanel = vgui.Create("DPanel", frame.mainContainer)
    btnPanel:Dock(BOTTOM)
    btnPanel:SetTall(cLib.Scale(40))
    btnPanel.Paint = nil
    
    local cancelBtn = vgui.Create("cLib.DButton", btnPanel)
    cancelBtn:SetText("Cancel")
    cancelBtn:Dock(LEFT)
    cancelBtn:SetWide(cLib.Scale(100))
    cancelBtn.DoClick = function() frame:Remove() end
    
    local okBtn = vgui.Create("cLib.DButton", btnPanel)
    okBtn:SetText("OK")
    okBtn:SetBackgroundColor(cLib.GetColor("cLib.accent"))
    okBtn:Dock(RIGHT)
    okBtn:SetWide(cLib.Scale(100))
    okBtn.DoClick = function()
        if callback then callback(picker:GetColor()) end
        frame:Remove()
    end
end