2013-10-18 20:38:07 +00:00
|
|
|
local Widget = require("ui/widget/widget")
|
2013-12-17 14:42:25 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2013-03-12 17:18:53 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
ProgressWidget shows a progress bar
|
|
|
|
--]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local ProgressWidget = Widget:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
margin_h = 3,
|
|
|
|
margin_v = 1,
|
|
|
|
radius = 2,
|
|
|
|
bordersize = 1,
|
2014-08-11 03:09:45 +00:00
|
|
|
toc_marker_width = DMINIBAR_TOC_MARKER_WIDTH,
|
2014-03-13 13:52:43 +00:00
|
|
|
bordercolor = 15,
|
|
|
|
bgcolor = 0,
|
|
|
|
rectcolor = 10,
|
|
|
|
percentage = nil,
|
2014-08-09 06:58:44 +00:00
|
|
|
TOC = {},
|
|
|
|
last = nil,
|
2013-03-12 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ProgressWidget:getSize()
|
2014-03-13 13:52:43 +00:00
|
|
|
return { w = self.width, h = self.height }
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ProgressWidget:paintTo(bb, x, y)
|
2014-03-13 13:52:43 +00:00
|
|
|
local my_size = self:getSize()
|
|
|
|
self.dimen = Geom:new{
|
|
|
|
x = x, y = y,
|
|
|
|
w = my_size.w,
|
2014-08-11 03:09:45 +00:00
|
|
|
h = my_size.h
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
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)
|
2014-08-09 06:58:44 +00:00
|
|
|
if DMINIBAR_PROGRESS_MARKER then
|
|
|
|
if #self.TOC > 0 then
|
|
|
|
for i=1, #self.TOC do
|
|
|
|
v = self.TOC[i]
|
|
|
|
bb:paintRect(x+(my_size.w-2*self.margin_h)*(v.page/self.last), y+self.margin_v+self.bordersize,
|
2014-08-11 03:09:45 +00:00
|
|
|
self.toc_marker_width,(my_size.h-2*(self.margin_v+self.bordersize)), self.bordercolor)
|
2014-08-09 06:58:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ProgressWidget:setPercentage(percentage)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.percentage = percentage
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ProgressWidget
|