|
|
@ -27,6 +27,7 @@ Example:
|
|
|
|
|
|
|
|
|
|
|
|
]]
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local BD = require("ui/bidi")
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Widget = require("ui/widget/widget")
|
|
|
|
local Widget = require("ui/widget/widget")
|
|
|
@ -46,6 +47,9 @@ local ProgressWidget = Widget:new{
|
|
|
|
ticks = nil,
|
|
|
|
ticks = nil,
|
|
|
|
tick_width = Screen:scaleBySize(3),
|
|
|
|
tick_width = Screen:scaleBySize(3),
|
|
|
|
last = nil,
|
|
|
|
last = nil,
|
|
|
|
|
|
|
|
fill_from_right = false,
|
|
|
|
|
|
|
|
allow_mirroring = true,
|
|
|
|
|
|
|
|
_mirroredUI = BD.mirroredUILayout(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ProgressWidget:getSize()
|
|
|
|
function ProgressWidget:getSize()
|
|
|
@ -69,17 +73,30 @@ function ProgressWidget:paintTo(bb, x, y)
|
|
|
|
self.bordersize, self.bordercolor, self.radius)
|
|
|
|
self.bordersize, self.bordercolor, self.radius)
|
|
|
|
-- paint percentage infill
|
|
|
|
-- paint percentage infill
|
|
|
|
if self.percentage >= 0 and self.percentage <= 1 then
|
|
|
|
if self.percentage >= 0 and self.percentage <= 1 then
|
|
|
|
bb:paintRect(x+self.margin_h, math.ceil(y+self.margin_v+self.bordersize),
|
|
|
|
if self.fill_from_right or (self._mirroredUI and not self.fill_from_right) then
|
|
|
|
|
|
|
|
bb:paintRect(x+self.margin_h + math.ceil((my_size.w-2*self.margin_h)*(1-self.percentage)),
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
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),
|
|
|
|
math.ceil((my_size.w-2*self.margin_h)*self.percentage),
|
|
|
|
my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor)
|
|
|
|
my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
if self.ticks and self.last and self.last > 0 then
|
|
|
|
if self.ticks and self.last and self.last > 0 then
|
|
|
|
local bar_width = (my_size.w-2*self.margin_h)
|
|
|
|
local bar_width = (my_size.w-2*self.margin_h)
|
|
|
|
local y_pos = y + self.margin_v + self.bordersize
|
|
|
|
local y_pos = y + self.margin_v + self.bordersize
|
|
|
|
local bar_height = my_size.h-2*(self.margin_v+self.bordersize)
|
|
|
|
local bar_height = my_size.h-2*(self.margin_v+self.bordersize)
|
|
|
|
for i=1, #self.ticks do
|
|
|
|
for i=1, #self.ticks do
|
|
|
|
|
|
|
|
local tick_x = bar_width*(self.ticks[i]/self.last)
|
|
|
|
|
|
|
|
if self._mirroredUI then
|
|
|
|
|
|
|
|
tick_x = bar_width - tick_x
|
|
|
|
|
|
|
|
end
|
|
|
|
bb:paintRect(
|
|
|
|
bb:paintRect(
|
|
|
|
x + bar_width*(self.ticks[i]/self.last) + self.margin_h,
|
|
|
|
x + self.margin_h + tick_x,
|
|
|
|
y_pos,
|
|
|
|
y_pos,
|
|
|
|
self.tick_width,
|
|
|
|
self.tick_width,
|
|
|
|
bar_height,
|
|
|
|
bar_height,
|
|
|
@ -92,6 +109,21 @@ function ProgressWidget:setPercentage(percentage)
|
|
|
|
self.percentage = percentage
|
|
|
|
self.percentage = percentage
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ProgressWidget:getPercentageFromPosition(pos)
|
|
|
|
|
|
|
|
if not pos or not pos.x then
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local width = self.dimen.w - 2*self.margin_h
|
|
|
|
|
|
|
|
local x = pos.x - self.dimen.x - self.margin_h
|
|
|
|
|
|
|
|
if x < 0 or x > width then
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if BD.mirroredUILayout() then
|
|
|
|
|
|
|
|
x = width - x
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return x / width
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function ProgressWidget:updateStyle(thick, height)
|
|
|
|
function ProgressWidget:updateStyle(thick, height)
|
|
|
|
if thick then
|
|
|
|
if thick then
|
|
|
|
if height then
|
|
|
|
if height then
|
|
|
|