Allow opening hold menu on non touch devices (#3765)

Emulate the hold touch behavior on non touch device by clicking the right key
ButtonTable: do not add vertical separator to the layout because the focus
manager can't traverse them. Add check to make disabled button non-clickable.
pull/3776/head
onde2rock 6 years ago committed by poire-z
parent 5e47a83e6a
commit 5fcb804d47

@ -41,7 +41,7 @@ function ButtonTable:init()
end
local row_cnt = #self.buttons
for i = 1, row_cnt do
self.buttons_layout[i] = {}
local buttons_layout_line = {}
local horizontal_group = HorizontalGroup:new{}
local row = self.buttons[i]
local column_cnt = #row
@ -69,7 +69,7 @@ function ButtonTable:init()
h = button_dim.h,
}
}
self.buttons_layout[i][j] = button
buttons_layout_line[j] = button
table.insert(horizontal_group, button)
if j < column_cnt then
table.insert(horizontal_group, vertical_sep)
@ -79,6 +79,10 @@ function ButtonTable:init()
if i < row_cnt then
self:addHorizontalSep(true, true, true)
end
if column_cnt > 0 then
--Only add line that are not separator to the focusmanager
table.insert(self.buttons_layout, buttons_layout_line)
end
end -- end for each button line
self:addHorizontalSep(true, false, false)
if Device:hasDPad() or Device:hasKeyboard() then
@ -111,7 +115,10 @@ function ButtonTable:addHorizontalSep(vspan_before, add_line, vspan_after, black
end
function ButtonTable:onSelectByKeyPress()
self:getFocusItem().callback()
local item = self:getFocusItem()
if item.enabled then
item.callback()
end
end
return ButtonTable

@ -1,7 +1,7 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local Event = require("ui/event")
local InputContainer = require("ui/widget/container/inputcontainer")
local logger = require("logger")
local UIManager = require("ui/uimanager")
--[[
Wrapper Widget that manages focus for a whole dialog
@ -56,16 +56,17 @@ function FocusManager:onFocusMove(args)
local current_item = self.layout[self.selected.y][self.selected.x]
while true do
if not self.layout[self.selected.y + dy] then
--vertical borders, try to wraparound
--horizontal border, try to wraparound
if not self:wrapAround(dy) then
break
end
elseif not self.layout[self.selected.y + dy][self.selected.x + dx] then
--vertical border, no wraparound
--vertical border, no wraparound
break
else
self.selected.y = self.selected.y + dy
self.selected.x = self.selected.x + dx
logger.dbg("Cursor position : ".. self.selected.y .." : "..self.selected.x)
end
if self.layout[self.selected.y][self.selected.x] ~= current_item

@ -793,6 +793,9 @@ function Menu:init()
self.key_events.Select = {
{"Press"}, doc = "select current menu item"
}
self.key_events.Right = {
{"Right"}, doc = "hold menu item"
}
end
@ -1088,6 +1091,14 @@ function Menu:onSelect()
return true
end
function Menu:onRight()
local item = self.item_table[(self.page-1)*self.perpage+self.selected.y]
if item then
self:onMenuHold(item)
end
return true
end
function Menu:onClose()
local table_length = #self.item_table_stack
if table_length == 0 then

Loading…
Cancel
Save