This commit is contained in:
airstruck
2015-10-25 16:23:24 -04:00
parent ae06e78054
commit c9414eec48

63
luigi/widget/stepper.lua Normal file
View File

@@ -0,0 +1,63 @@
local Widget = require((...):gsub('%.[^.]*$', ''))
local Stepper = Widget:extend()
function Stepper:constructor (layout, data)
Widget.constructor(self, layout, data)
self.flow = 'x'
self.index = 1
local left = self:addChild {
type = 'button',
text = '<',
align = 'middle center',
margin = 0,
}
local view = self:addChild {
align = 'middle center',
margin = 0,
}
local right = self:addChild {
type = 'button',
text = '>',
align = 'middle center',
margin = 0,
}
self:onReshape(function (event)
left.width = left:getHeight()
right.width = right:getHeight()
end)
local function updateValue ()
if not self.options then return end
local option = self.options[self.index]
self.value = option.value
view.text = option.text
end
left:onPress(function (event)
if not self.options then return end
self.index = self.index - 1
if self.index < 1 then
self.index = #self.options
end
updateValue()
end)
right:onPress(function (event)
if not self.options then return end
self.index = self.index + 1
if self.index > #self.options then
self.index = 1
end
updateValue()
end)
updateValue()
end
return Stepper