2019-06-28 17:50:02 +00:00
|
|
|
local class = require('opus.class')
|
|
|
|
local UI = require('opus.ui')
|
2019-02-06 04:03:57 +00:00
|
|
|
|
|
|
|
local colors = _G.colors
|
|
|
|
|
|
|
|
UI.ProgressBar = class(UI.Window)
|
|
|
|
UI.ProgressBar.defaults = {
|
|
|
|
UIElement = 'ProgressBar',
|
|
|
|
backgroundColor = colors.gray,
|
|
|
|
height = 1,
|
2019-07-02 14:19:08 +00:00
|
|
|
progressColor = colors.lime,
|
|
|
|
progressChar = UI.extChars and '\153' or ' ',
|
|
|
|
fillChar = ' ',
|
|
|
|
fillColor = colors.gray,
|
|
|
|
textColor = colors.green,
|
2019-02-06 04:03:57 +00:00
|
|
|
value = 0,
|
|
|
|
}
|
|
|
|
function UI.ProgressBar:draw()
|
|
|
|
local width = math.ceil(self.value / 100 * self.width)
|
2019-07-02 14:19:08 +00:00
|
|
|
|
|
|
|
local filler = string.rep(self.fillChar, self.width)
|
|
|
|
local progress = string.rep(self.progressChar, width)
|
|
|
|
|
|
|
|
for i = 1, self.height do
|
|
|
|
self:write(1, i, filler, nil, self.fillColor)
|
|
|
|
self:write(1, i, progress, self.progressColor)
|
|
|
|
end
|
2019-02-06 04:03:57 +00:00
|
|
|
end
|
2019-11-15 19:51:44 +00:00
|
|
|
|
|
|
|
function UI.ProgressBar.example()
|
|
|
|
local Event = require('opus.event')
|
|
|
|
return UI.ProgressBar {
|
|
|
|
x = 2, ex = -2, y = 2,
|
|
|
|
focus = function() end,
|
|
|
|
enable = function(self)
|
|
|
|
Event.onInterval(.25, function()
|
|
|
|
self.value = self.value == 100 and 0 or self.value + 5
|
|
|
|
self:draw()
|
|
|
|
self:sync()
|
|
|
|
end)
|
|
|
|
return UI.ProgressBar.enable(self)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|