cLib.DProgressBar
Animated progress bar with multiple styles.
Basic Usage
local progress = vgui.Create("cLib.DProgressBar", parent)
progress:SetSize(cLib.Scale(300), cLib.Scale(20))
progress:SetProgress(0.75) -- 75%Methods
| Method | Description |
|---|---|
SetProgress(0-1) | Set progress (0 to 1) |
GetProgress() | Get progress value |
SetShowLabel(bool) | Show percentage text |
SetLabelFormat(string) | Format string ("%d%%") |
SetStyle(string) | "default", "striped", "animated" |
SetFillColor(Color) | Progress fill color |
SetBackgroundColor(Color) | Background color |
SetTextColor(Color) | Label text color |
SetRoundness(number) | Corner roundness |
Styles
-- Default (solid fill)
progress:SetStyle("default")
-- Striped
progress:SetStyle("striped")
-- Animated (moving stripes)
progress:SetStyle("animated")Custom Colors
local progress = vgui.Create("cLib.DProgressBar", parent)
progress:SetProgress(0.5)
progress:SetFillColor(cLib.GetColor("cLib.success")) -- Green
progress:SetBackgroundColor(Color(40, 40, 45))With Label
local progress = vgui.Create("cLib.DProgressBar", parent)
progress:SetShowLabel(true)
progress:SetLabelFormat("%d%%") -- Shows "75%"
progress:SetProgress(0.75)
-- Custom format
progress:SetLabelFormat("%.1f%%") -- Shows "75.0%"Loading Bar Example
function ShowLoadingBar(parent, onComplete)
local bar = vgui.Create("cLib.DProgressBar", parent)
bar:SetSize(cLib.Scale(400), cLib.Scale(25))
bar:Center()
bar:SetStyle("animated")
bar:SetShowLabel(true)
bar:SetProgress(0)
local progress = 0
timer.Create("LoadingProgress", 0.05, 0, function()
if not IsValid(bar) then
timer.Remove("LoadingProgress")
return
end
progress = progress + math.random(1, 3) / 100
bar:SetProgress(math.min(progress, 1))
if progress >= 1 then
timer.Remove("LoadingProgress")
if onComplete then onComplete() end
end
end)
return bar
endHealth/Resource Bar
function CreateHealthBar(parent, entity)
local bar = vgui.Create("cLib.DProgressBar", parent)
bar:SetSize(cLib.Scale(150), cLib.Scale(15))
bar:SetShowLabel(true)
bar:SetLabelFormat("%d HP")
bar:SetRoundness(2)
bar.Think = function(self)
if not IsValid(entity) then return end
local health = entity:Health()
local maxHealth = entity:GetMaxHealth()
local percent = health / maxHealth
self:SetProgress(percent)
self:SetLabelFormat(health .. "/" .. maxHealth)
-- Color based on health
if percent > 0.6 then
self:SetFillColor(Color(80, 200, 120)) -- Green
elseif percent > 0.3 then
self:SetFillColor(Color(255, 180, 50)) -- Orange
else
self:SetFillColor(Color(255, 80, 80)) -- Red
end
end
return bar
end