deploy: 1c90c6cf04
This commit is contained in:
@@ -1,41 +1,24 @@
|
||||
local VisualElement = require("elements/VisualElement")
|
||||
# ProgressBar : VisualElement
|
||||
|
||||
---@class ProgressBar : VisualElement
|
||||
local ProgressBar = setmetatable({}, VisualElement)
|
||||
ProgressBar.__index = ProgressBar
|
||||
## Properties
|
||||
|
||||
---@property progress number Current progress (0-100)
|
||||
ProgressBar.defineProperty(ProgressBar, "progress", {default = 0, type = "number", canTriggerRender = true})
|
||||
---@property showPercentage boolean Show percentage text
|
||||
ProgressBar.defineProperty(ProgressBar, "showPercentage", {default = false, type = "boolean"})
|
||||
---@property progressColor color Progress bar color
|
||||
ProgressBar.defineProperty(ProgressBar, "progressColor", {default = colors.lime, type = "number"})
|
||||
|Property|Type|Default|Description|
|
||||
|---|---|---|---|
|
||||
|progress|number|Current|progress (0-100)
|
||||
|showPercentage|boolean|Show|percentage text
|
||||
|progressColor|color|Progress|bar color
|
||||
|
||||
function ProgressBar.new()
|
||||
local self = setmetatable({}, ProgressBar):__init()
|
||||
self.set("width", 10)
|
||||
self.set("height", 1)
|
||||
return self
|
||||
end
|
||||
## Functions
|
||||
|
||||
function ProgressBar:init(props, basalt)
|
||||
VisualElement.init(self, props, basalt)
|
||||
self.set("type", "ProgressBar")
|
||||
end
|
||||
|Method|Returns|Description|
|
||||
|---|---|---|
|
||||
|[ProgressBar.new](#ProgressBar.new)|-|
|
||||
|[ProgressBar:init](#ProgressBar:init)|-|
|
||||
|[ProgressBar:render](#ProgressBar:render)|-|
|
||||
|
||||
function ProgressBar:render()
|
||||
VisualElement.render(self)
|
||||
local width = self.get("width")
|
||||
local progress = math.min(100, math.max(0, self.get("progress")))
|
||||
local fillWidth = math.floor((width * progress) / 100)
|
||||
## ProgressBar.new()
|
||||
|
||||
self:textBg(1, 1, string.rep(" ", fillWidth), self.get("progressColor"))
|
||||
## ProgressBar:init()
|
||||
|
||||
if self.get("showPercentage") then
|
||||
local text = tostring(progress).."%"
|
||||
local x = math.floor((width - #text) / 2) + 1
|
||||
self:textFg(x, 1, text, self.get("foreground"))
|
||||
end
|
||||
end
|
||||
## ProgressBar:render()
|
||||
|
||||
return ProgressBar
|
||||
Reference in New Issue
Block a user