support vertical progress

This commit is contained in:
airstruck
2015-12-07 22:11:58 -05:00
parent c43d8bcf22
commit d11ea06503
2 changed files with 17 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ end)
layout.flowToggle:onChange(function (event) layout.flowToggle:onChange(function (event)
layout.flowTest.flow = event.value and 'x' or 'y' layout.flowTest.flow = event.value and 'x' or 'y'
layout.slidey.flow = event.value and 'y' or 'x' layout.slidey.flow = event.value and 'y' or 'x'
layout.progressBar.flow = event.value and 'y' or 'x'
end) end)
layout.newButton:onPress(function (event) layout.newButton:onPress(function (event)

View File

@@ -9,11 +9,12 @@ between 0 and 1 (inclusive) to change the width of the bar.
return function (self) return function (self)
self.value = 0 self.value = 0
self.flow = 'x' -- TODO: support vertical progress?
local pad = self:addChild {
width = 0,
}
local bar = self:addChild { local bar = self:addChild {
type = 'progress.bar', type = 'progress.bar',
width = 0,
} }
self:onChange(function () self:onChange(function ()
@@ -23,8 +24,18 @@ return function (self)
self:onReshape(function () self:onReshape(function ()
local x1, y1, w, h = self:getRectangle(true, true) local x1, y1, w, h = self:getRectangle(true, true)
local x2, y2 = x1 + w, y1 + h local x2, y2 = x1 + w, y1 + h
local min = bar.minwidth if self.flow == 'x' then
x1 = x1 + min local min = bar.minwidth or 0
bar.width = self.value * (x2 - x1) + min x1 = x1 + min
bar.width = self.value * (x2 - x1) + min
bar.height = false
pad.height = 0
else
local min = bar.minheight or 0
y1 = y1 + min
bar.width = false
bar.height = false
pad.height = h - (self.value * (y2 - y1) + min)
end
end) end)
end end