hotkeys use modifiers

This commit is contained in:
airstruck
2015-11-11 23:49:54 -05:00
parent 68a250e273
commit 6aaa128463
13 changed files with 205 additions and 113 deletions
+18 -23
View File
@@ -1,22 +1,17 @@
return function (self)
self.items = {}
self.index = 1
self.flow = 'x' -- TODO: support vertical stepper
local decrement = self:addChild {
type = 'stepper.left',
}
for index, child in ipairs(self) do
child.type = child.type or 'stepper.item'
self.items[index] = child
self[index] = nil
end
local view = self:addChild {
type = 'text',
align = 'middle center',
margin = 0,
canFocus = false,
}
local increment = self:addChild {
type = 'stepper.right',
}
local decrement = self:addChild { type = 'stepper.left' }
local view = self:addChild()
local increment = self:addChild { type = 'stepper.right' }
self:onReshape(function (event)
decrement.width = decrement:getHeight()
@@ -24,30 +19,30 @@ return function (self)
end)
local function updateValue ()
if not self.options then return end
local option = self.options[self.index]
self:setValue(option.value)
view.text = option.text
local item = self.items[self.index]
self.value = item.value
view[1] = nil
view:addChild(item)
item:reshape()
end
decrement:onPress(function (event)
if not self.options then return end
if not self.items then return end
self.index = self.index - 1
if self.index < 1 then
self.index = #self.options
self.index = #self.items
end
updateValue()
end)
increment:onPress(function (event)
if not self.options then return end
if not self.items then return end
self.index = self.index + 1
if self.index > #self.options then
if self.index > #self.items then
self.index = 1
end
updateValue()
end)
updateValue()
end