cLib.DNumSlider

VGUI - Input Updated: Dec 10, 2025

cLib.DNumSlider

Numeric slider with text input.

Basic Usage

local slider = vgui.Create("cLib.DNumSlider", parent)
slider:SetSize(cLib.Scale(300), cLib.Scale(40))
slider:SetText("Volume")
slider:SetMin(0)
slider:SetMax(100)
slider:SetValue(50)
slider:SetDecimals(0)

slider.OnValueChanged = function(self, value)
    SetVolume(value / 100)
end

Methods

MethodDescription
SetText(string)Label text
SetMin(number)Minimum value
SetMax(number)Maximum value
SetValue(number)Current value
GetValue()Get value
SetDecimals(number)Decimal places
SetDefaultValue(number)Default for reset

Different Ranges

-- Percentage (0-100)
local percent = vgui.Create("cLib.DNumSlider", parent)
percent:SetText("Opacity")
percent:SetMin(0)
percent:SetMax(100)
percent:SetDecimals(0)
percent:SetValue(100)

-- Float (0-1)
local float = vgui.Create("cLib.DNumSlider", parent)
float:SetText("Scale")
float:SetMin(0)
float:SetMax(1)
float:SetDecimals(2)
float:SetValue(1)

-- Large range
local large = vgui.Create("cLib.DNumSlider", parent)
large:SetText("Max Health")
large:SetMin(100)
large:SetMax(10000)
large:SetDecimals(0)
large:SetValue(100)

-- Negative values
local offset = vgui.Create("cLib.DNumSlider", parent)
offset:SetText("X Offset")
offset:SetMin(-100)
offset:SetMax(100)
offset:SetDecimals(0)
offset:SetValue(0)

ConVar Binding

local fov = vgui.Create("cLib.DNumSlider", parent)
fov:SetText("Field of View")
fov:SetMin(60)
fov:SetMax(120)
fov:SetDecimals(0)
fov:SetValue(GetConVar("fov_desired"):GetInt())
fov:SetDefaultValue(90)

fov.OnValueChanged = function(self, value)
    RunConsoleCommand("fov_desired", math.floor(value))
end

Settings Panel

function CreateAudioSettings(parent)
    local master = vgui.Create("cLib.DNumSlider", parent)
    master:SetText("Master Volume")
    master:SetMin(0)
    master:SetMax(100)
    master:SetValue(GetConVar("volume"):GetFloat() * 100)
    master:Dock(TOP)
    master:DockMargin(0, 0, 0, cLib.Scale(10))
    
    master.OnValueChanged = function(s, v)
        RunConsoleCommand("volume", v / 100)
    end
    
    local music = vgui.Create("cLib.DNumSlider", parent)
    music:SetText("Music Volume")
    music:SetMin(0)
    music:SetMax(100)
    music:SetValue(GetConVar("snd_musicvolume"):GetFloat() * 100)
    music:Dock(TOP)
    music:DockMargin(0, 0, 0, cLib.Scale(10))
    
    music.OnValueChanged = function(s, v)
        RunConsoleCommand("snd_musicvolume", v / 100)
    end
end