mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 10:26:43 +00:00
58 lines
1.3 KiB
Lua
58 lines
1.3 KiB
Lua
return function (self)
|
|
|
|
self.index = 1
|
|
self.flow = 'x' -- TODO: support vertical stepper
|
|
|
|
local decrement = self:addChild {
|
|
type = 'button',
|
|
text = '<',
|
|
align = 'middle center',
|
|
margin = 0,
|
|
}
|
|
|
|
local view = self:addChild {
|
|
align = 'middle center',
|
|
margin = 0,
|
|
}
|
|
|
|
local increment = self:addChild {
|
|
type = 'button',
|
|
text = '>',
|
|
align = 'middle center',
|
|
margin = 0,
|
|
}
|
|
|
|
self:onReshape(function (event)
|
|
decrement.width = decrement:getHeight()
|
|
increment.width = increment: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
|
|
|
|
decrement: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)
|
|
|
|
increment: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
|