1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-24 12:17:40 +00:00

overview cleanup + chooser better events

This commit is contained in:
kepler155c@gmail.com
2018-11-12 20:21:35 -05:00
parent f9359cf77f
commit 62ac7a52ec
2 changed files with 17 additions and 16 deletions

View File

@@ -3001,22 +3001,26 @@ function UI.Chooser:eventHandler(event)
if event.type == 'key' then
if event.key == 'right' or event.key == 'space' then
local _,k = Util.find(self.choices, 'value', self.value)
local choice
if k and k < #self.choices then
self.value = self.choices[k+1].value
choice = self.choices[k+1]
else
self.value = self.choices[1].value
choice = self.choices[1]
end
self:emit({ type = 'choice_change', value = self.value })
self.value = choice.value
self:emit({ type = 'choice_change', value = self.value, element = self, choice = choice })
self:draw()
return true
elseif event.key == 'left' then
local _,k = Util.find(self.choices, 'value', self.value)
local choice
if k and k > 1 then
self.value = self.choices[k-1].value
choice = self.choices[k-1]
else
self.value = self.choices[#self.choices].value
choice = self.choices[#self.choices]
end
self:emit({ type = 'choice_change', value = self.value })
self.value = choice.value
self:emit({ type = 'choice_change', value = self.value, element = self, choice = choice })
self:draw()
return true
end