|
|
|
@ -1,10 +1,36 @@
|
|
|
|
|
--[[--
|
|
|
|
|
Widget for displaying progress bar.
|
|
|
|
|
|
|
|
|
|
Configurable attributes:
|
|
|
|
|
|
|
|
|
|
* width
|
|
|
|
|
* height
|
|
|
|
|
* margin_v -- vertical margin for solid infill
|
|
|
|
|
* margin_h -- horizontal margin for solid infill
|
|
|
|
|
* radius
|
|
|
|
|
* bordersize
|
|
|
|
|
* bordercolor
|
|
|
|
|
* bgcolor
|
|
|
|
|
* rectcolor -- infill color
|
|
|
|
|
* ticks (list) -- default to nil, use this if you want to insert markers
|
|
|
|
|
* tick_width
|
|
|
|
|
* last -- maximum tick
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
local foo_bar = ProgressWidget:new{
|
|
|
|
|
width = 400,
|
|
|
|
|
height = 10,
|
|
|
|
|
percentage = 50/100,
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(foo_bar)
|
|
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
local Widget = require("ui/widget/widget")
|
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
|
|
|
|
|
|
--[[
|
|
|
|
|
ProgressWidget shows a progress bar
|
|
|
|
|
--]]
|
|
|
|
|
local ProgressWidget = Widget:new{
|
|
|
|
|
width = nil,
|
|
|
|
|
height = nil,
|
|
|
|
@ -16,7 +42,7 @@ local ProgressWidget = Widget:new{
|
|
|
|
|
bgcolor = Blitbuffer.COLOR_WHITE,
|
|
|
|
|
rectcolor = Blitbuffer.gray(0.7),
|
|
|
|
|
percentage = nil,
|
|
|
|
|
ticks = {},
|
|
|
|
|
ticks = nil,
|
|
|
|
|
tick_width = 3,
|
|
|
|
|
last = nil,
|
|
|
|
|
}
|
|
|
|
@ -32,18 +58,26 @@ function ProgressWidget:paintTo(bb, x, y)
|
|
|
|
|
w = my_size.w,
|
|
|
|
|
h = my_size.h
|
|
|
|
|
}
|
|
|
|
|
-- fill background
|
|
|
|
|
bb:paintRoundedRect(x, y, my_size.w, my_size.h, self.bgcolor, self.radius)
|
|
|
|
|
bb:paintBorder(x, y, my_size.w, my_size.h,
|
|
|
|
|
self.bordersize, self.bordercolor, self.radius)
|
|
|
|
|
bb:paintRect(x+self.margin_h, y+self.margin_v+self.bordersize,
|
|
|
|
|
(my_size.w-2*self.margin_h)*self.percentage,
|
|
|
|
|
(my_size.h-2*(self.margin_v+self.bordersize)), self.rectcolor)
|
|
|
|
|
for i=1, #self.ticks do
|
|
|
|
|
local page = self.ticks[i]
|
|
|
|
|
bb:paintRect(
|
|
|
|
|
-- paint border
|
|
|
|
|
bb:paintBorder(x, y,
|
|
|
|
|
my_size.w, my_size.h,
|
|
|
|
|
self.bordersize, self.bordercolor, self.radius)
|
|
|
|
|
-- paint percentage infill
|
|
|
|
|
bb:paintRect(x+self.margin_h, math.ceil(y+self.margin_v+self.bordersize),
|
|
|
|
|
math.ceil((my_size.w-2*self.margin_h)*self.percentage),
|
|
|
|
|
my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor)
|
|
|
|
|
if self.ticks then
|
|
|
|
|
for i=1, #self.ticks do
|
|
|
|
|
local page = self.ticks[i]
|
|
|
|
|
bb:paintRect(
|
|
|
|
|
x + (my_size.w-2*self.margin_h)*(page/self.last),
|
|
|
|
|
y + self.margin_v + self.bordersize, self.tick_width,
|
|
|
|
|
(my_size.h-2*(self.margin_v+self.bordersize)), self.bordercolor)
|
|
|
|
|
y + self.margin_v + self.bordersize,
|
|
|
|
|
self.tick_width,
|
|
|
|
|
my_size.h-2*(self.margin_v+self.bordersize),
|
|
|
|
|
self.bordercolor)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|