if toc item has expand/collapse state and tap select on the left side
the state switch action is triggered, otherwise goto the
linked page.
pull/1025/head
chrox 10 years ago
parent 1cb3c85f34
commit c994e30cff

@ -304,8 +304,15 @@ function ReaderToc:onShowToc()
toc_menu, toc_menu,
} }
function toc_menu:onMenuChoice(item) function toc_menu:onMenuSelect(item, pos)
self.ui:handleEvent(Event:new("GotoPage", item.page)) -- if toc item has expand/collapse state and tap select on the left side
-- the state switch action is triggered, otherwise goto the linked page
if item.state and pos.x < 0.5 then
item.state.callback()
else
toc_menu:close_callback()
self.ui:handleEvent(Event:new("GotoPage", item.page))
end
end end
toc_menu.close_callback = function() toc_menu.close_callback = function()

@ -270,24 +270,34 @@ function MenuItem:onShowItemDetail()
return true return true
end end
function MenuItem:onTapSelect() function MenuItem:getGesPosition(ges)
local dimen = self[1].dimen
return {
x = (ges.pos.x - dimen.x)/dimen.w,
y = (ges.pos.y - dimen.y)/dimen.h,
}
end
function MenuItem:onTapSelect(arg, ges)
local pos = self:getGesPosition(ges)
self[1].invert = true self[1].invert = true
UIManager:setDirty(self.show_parent, "partial") UIManager:setDirty(self.show_parent, "partial")
UIManager:scheduleIn(0.1, function() UIManager:scheduleIn(0.1, function()
self[1].invert = false self[1].invert = false
UIManager:setDirty(self.show_parent, "partial") UIManager:setDirty(self.show_parent, "partial")
self.menu:onMenuSelect(self.table) self.menu:onMenuSelect(self.table, pos)
end) end)
return true return true
end end
function MenuItem:onHoldSelect() function MenuItem:onHoldSelect(arg, ges)
local pos = self:getGesPosition(ges)
self[1].invert = true self[1].invert = true
UIManager:setDirty(self.show_parent, "partial") UIManager:setDirty(self.show_parent, "partial")
UIManager:scheduleIn(0.1, function() UIManager:scheduleIn(0.1, function()
self[1].invert = false self[1].invert = false
UIManager:setDirty(self.show_parent, "partial") UIManager:setDirty(self.show_parent, "partial")
self.menu:onMenuHold(self.table) self.menu:onMenuHold(self.table, pos)
end) end)
return true return true
end end

Loading…
Cancel
Save