Fix crash with keyboard navigation of onHold buttontables (#3307)

* Fix crash with keyboard navigation of onHold buttontables

Would crash when encountering a separator or when the number
of buttons in a row changes.

* Reset previous selected item on new buttontable
pull/3314/head
poire-z 7 years ago committed by Frans de Jonge
parent b7785753c6
commit e6fcea6e26

@ -27,6 +27,7 @@ local ButtonTable = FocusManager:new{
}
function ButtonTable:init()
self.selected = { x = 1, y = 1 }
self.buttons_layout = {}
self.container = VerticalGroup:new{ width = self.width }
table.insert(self, self.container)

@ -73,8 +73,15 @@ function FocusManager:onFocusMove(args)
end
else
self.selected.y = self.selected.y + dy
if #self.layout[self.selected.y] == 0 then -- horizontal separator
self.selected.y = self.selected.y + dy -- skip it
end
end
self.selected.x = self.selected.x + dx
if self.selected.x > #self.layout[self.selected.y] then
-- smaller nb of items on new row than on prev row
self.selected.x = #self.layout[self.selected.y]
end
if self.layout[self.selected.y][self.selected.x] ~= current_item
or not self.layout[self.selected.y][self.selected.x].is_inactive then

Loading…
Cancel
Save