-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathui_progressbar.lua
62 lines (47 loc) · 1.18 KB
/
ui_progressbar.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--Progress Bar widget.
--Written by Cosmin Apreutesei. Public Domain.
local ui = require'ui'
local progressbar = ui.layer:subclass'progressbar'
ui.progressbar = progressbar
progressbar.iswidget = true
progressbar.progress = 0
--progressbar.layout = 'textbox'
progressbar.h = 24
progressbar.text_operator = 'xor'
progressbar.border_width = 1
progressbar.border_color = '#333'
function progressbar:format_text(progress)
return string.format('%d%%', progress * 100)
end
function progressbar:after_sync()
self.text = self:format_text(self.progress)
end
local bar = ui.layer:subclass'progressbar_bar'
progressbar.bar_class = bar
bar.background_color = '#fff'
function progressbar:create_bar()
return self.bar_class(self.ui, {
parent = self,
iswidget = false,
progressbar = self,
}, self.bar)
end
function bar:after_sync()
local pb = self.progressbar
self.h = pb.ch
self.w = pb.cw * pb.progress
end
function progressbar:after_init()
self.bar = self:create_bar()
end
if not ... then require('ui_demo')(function(ui, win)
local b1 = ui:progressbar{
parent = win,
x = 100, y = 100, w = 200,
progress = .48,
text_color = '#f0f',
bar = {
background_color = '#ff0',
},
}
end) end