Docs update + some element updates

This commit is contained in:
Robert Jelic
2025-04-06 00:57:19 +02:00
parent 5ccd201be0
commit f911e9bce8
11 changed files with 159 additions and 36 deletions

View File

@@ -1,7 +1,11 @@
local VisualElement = require("elements/VisualElement")
local tHex = require("libraries/colorHex")
--- This is the progress bar class. It provides a visual representation of progress
--- with optional percentage display and customizable colors.
--- @usage local progressBar = main:addProgressBar()
--- @usage progressBar:setDirection("up")
--- @usage progressBar:setProgress(50)
---@class ProgressBar : VisualElement
local ProgressBar = setmetatable({}, VisualElement)
ProgressBar.__index = ProgressBar
@@ -12,6 +16,8 @@ ProgressBar.defineProperty(ProgressBar, "progress", {default = 0, type = "number
ProgressBar.defineProperty(ProgressBar, "showPercentage", {default = false, type = "boolean"})
---@property progressColor color lime The color used for the filled portion of the progress bar
ProgressBar.defineProperty(ProgressBar, "progressColor", {default = colors.black, type = "color"})
---@property direction string right The direction of the progress bar ("up", "down", "left", "right")
ProgressBar.defineProperty(ProgressBar, "direction", {default = "right", type = "string"})
--- Creates a new ProgressBar instance
--- @shortDescription Creates a new ProgressBar instance
@@ -19,8 +25,8 @@ ProgressBar.defineProperty(ProgressBar, "progressColor", {default = colors.black
--- @private
function ProgressBar.new()
local self = setmetatable({}, ProgressBar):__init()
self.set("width", 10)
self.set("height", 1)
self.set("width", 25)
self.set("height", 3)
return self
end
@@ -39,17 +45,28 @@ end
function ProgressBar:render()
VisualElement.render(self)
local width = self.get("width")
local height = self.get("height")
local progress = math.min(100, math.max(0, self.get("progress")))
local fillWidth = math.floor((width * progress) / 100)
local fillHeight = math.floor((height * progress) / 100)
local direction = self.get("direction")
local progressColor = self.get("progressColor")
for i = 1, self.get("height") do
self:textBg(1, i, string.rep(" ", fillWidth), self.get("progressColor"))
if direction == "right" then
self:multiBlit(1, 1, fillWidth, height, " ", tHex[self.get("foreground")], tHex[progressColor])
elseif direction == "left" then
self:multiBlit(width - fillWidth + 1, 1, fillWidth, height, " ", tHex[self.get("foreground")], tHex[progressColor])
elseif direction == "up" then
self:multiBlit(1, height - fillHeight + 1, width, fillHeight, " ", tHex[self.get("foreground")], tHex[progressColor])
elseif direction == "down" then
self:multiBlit(1, 1, width, fillHeight, " ", tHex[self.get("foreground")], tHex[progressColor])
end
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"))
local y = math.floor((height - 1) / 2) + 1
self:textFg(x, y, text, self.get("foreground"))
end
end