2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
2012-01-10 23:13:40 +01:00
|
|
|
UIProgressBar = extends(UIWidget)
|
|
|
|
|
|
|
|
function UIProgressBar.create()
|
|
|
|
local progressbar = UIProgressBar.internalCreate()
|
|
|
|
progressbar:setFocusable(false)
|
|
|
|
progressbar:setPhantom(true)
|
2012-03-22 22:47:52 +01:00
|
|
|
progressbar.percent = 0
|
2012-01-15 16:13:22 +01:00
|
|
|
progressbar:updateBackground()
|
2012-01-10 23:13:40 +01:00
|
|
|
return progressbar
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIProgressBar:setPercent(percent)
|
2012-03-22 22:47:52 +01:00
|
|
|
self.percent = math.max(math.min(percent, 100), 0)
|
2012-01-15 16:13:22 +01:00
|
|
|
self:updateBackground()
|
2012-01-10 23:13:40 +01:00
|
|
|
end
|
|
|
|
|
2012-01-15 16:13:22 +01:00
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
function UIProgressBar:getPercent()
|
2012-03-22 22:47:52 +01:00
|
|
|
return self.percent
|
2012-01-15 16:13:22 +01:00
|
|
|
end
|
|
|
|
|
2012-06-08 22:58:24 +02:00
|
|
|
function UIProgressBar:getPercentPixels()
|
|
|
|
return 100 / self:getWidth()
|
|
|
|
end
|
|
|
|
|
2012-01-15 16:13:22 +01:00
|
|
|
function UIProgressBar:updateBackground()
|
2012-06-08 22:58:24 +02:00
|
|
|
local width = math.round(math.max((self.percent * self:getWidth())/100, 1))
|
2012-01-15 16:13:22 +01:00
|
|
|
local height = self:getHeight()
|
|
|
|
self:setBackgroundSize({width=width, height=height})
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function UIProgressBar:onGeometryChange(oldRect, newRect)
|
|
|
|
self:updateBackground()
|
2012-01-10 23:13:40 +01:00
|
|
|
end
|