mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add toc menu for touch UI
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
ReaderToc = InputContainer:new{
|
||||
key_events = {
|
||||
ShowToc = { {"T"}, doc = "show Table of Content menu"},
|
||||
},
|
||||
dimen = Geom:new{ w = Screen:getWidth()-20, h = Screen:getHeight()-20},
|
||||
toc_menu_title = "Table of contents",
|
||||
current_page = 0,
|
||||
current_pos = 0,
|
||||
}
|
||||
|
||||
function ReaderToc:init()
|
||||
if not Device:hasNoKeyboard() then
|
||||
self.key_events = {
|
||||
ShowToc = {
|
||||
{ "T" },
|
||||
doc = "show Table of Content menu" },
|
||||
}
|
||||
end
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
function ReaderToc:cleanUpTocTitle(title)
|
||||
return (title:gsub("\13", ""))
|
||||
end
|
||||
@@ -56,17 +64,29 @@ function ReaderToc:onShowToc()
|
||||
for _,v in ipairs(items) do
|
||||
v.text = (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title)
|
||||
end
|
||||
|
||||
local toc_menu = Menu:new{
|
||||
title = "Table of Contents",
|
||||
item_table = items,
|
||||
dimen = self.dimen,
|
||||
ui = self.ui
|
||||
ui = self.ui,
|
||||
dimen = Geom:new{
|
||||
w = Screen:getWidth()-20,
|
||||
h = Screen:getHeight()-20
|
||||
},
|
||||
}
|
||||
function toc_menu:onMenuChoice(item)
|
||||
self.ui:handleEvent(Event:new("PageUpdate", item.page))
|
||||
end
|
||||
|
||||
UIManager:show(toc_menu)
|
||||
local menu_container = CenterContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
toc_menu,
|
||||
}
|
||||
toc_menu.close_callback = function()
|
||||
UIManager:close(menu_container)
|
||||
end
|
||||
|
||||
UIManager:show(menu_container)
|
||||
end
|
||||
|
||||
function ReaderToc:onSetDimensions(dimen)
|
||||
@@ -81,4 +101,12 @@ function ReaderToc:onPosUpdate(new_pos)
|
||||
self.current_pos = new_pos
|
||||
end
|
||||
|
||||
|
||||
function ReaderToc:addToMainMenu(item_table)
|
||||
-- insert table to main reader menu
|
||||
table.insert(item_table, {
|
||||
text = self.toc_menu_title,
|
||||
callback = function()
|
||||
self:onShowToc()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -56,18 +56,18 @@ function ReaderUI:init()
|
||||
view = self[1],
|
||||
ui = self
|
||||
}
|
||||
-- reader menu controller
|
||||
self[3] = ReaderMenu:new{
|
||||
view = self[1],
|
||||
ui = self
|
||||
}
|
||||
self.menu = self[3] -- hold reference to menu widget
|
||||
-- Toc menu controller
|
||||
self[3] = ReaderToc:new{
|
||||
self[4] = ReaderToc:new{
|
||||
dialog = self.dialog,
|
||||
view = self[1],
|
||||
ui = self
|
||||
}
|
||||
-- reader menu controller
|
||||
self[4] = ReaderMenu:new{
|
||||
view = self[1],
|
||||
ui = self
|
||||
}
|
||||
self.menu = self[4] -- hold reference to menu widget
|
||||
|
||||
if self.document.info.has_pages then
|
||||
-- for page specific controller
|
||||
|
||||
Reference in New Issue
Block a user