mirror of
https://github.com/koreader/koreader.git
synced 2025-12-18 12:02:09 +01:00
add toc menu support for readerui
This commit is contained in:
@@ -92,6 +92,10 @@ function Document:getPageDimensions(pageno, zoom, rotation)
|
||||
return native_dimen
|
||||
end
|
||||
|
||||
function Document:getToc()
|
||||
return self._document:getToc()
|
||||
end
|
||||
|
||||
-- load implementations:
|
||||
|
||||
require "document/pdfdocument"
|
||||
|
||||
36
frontend/ui/reader/readertoc.lua
Normal file
36
frontend/ui/reader/readertoc.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
ReaderToc = InputContainer:new{
|
||||
key_events = {
|
||||
ShowToc = { {"T"}, doc = "show Table of Content menu"},
|
||||
},
|
||||
dimen = Geom:new{ w = G_width-20, h = G_height-20},
|
||||
}
|
||||
|
||||
function ReaderToc:cleanUpTocTitle(title)
|
||||
return title:gsub("\13", "")
|
||||
end
|
||||
|
||||
function ReaderToc:onSetDimensions(dimen)
|
||||
self.dimen = dimen
|
||||
end
|
||||
|
||||
function ReaderToc:onShowToc()
|
||||
function callback(item)
|
||||
self.ui:handleEvent(Event:new("PageUpdate", item.page))
|
||||
end
|
||||
|
||||
local items = self.ui.document:getToc()
|
||||
-- build menu items
|
||||
for _,v in ipairs(items) do
|
||||
v.text = (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title)
|
||||
end
|
||||
toc_menu = Menu:new{
|
||||
title = "Table of Contents",
|
||||
item_table = items,
|
||||
width = self.dimen.w,
|
||||
height = self.dimen.h,
|
||||
on_select_callback = callback,
|
||||
}
|
||||
|
||||
UIManager:show(toc_menu)
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ require "ui/reader/readerzooming"
|
||||
require "ui/reader/readerpanning"
|
||||
require "ui/reader/readerrotation"
|
||||
require "ui/reader/readerpaging"
|
||||
require "ui/reader/readertoc"
|
||||
|
||||
--[[
|
||||
This is an abstraction for a reader interface
|
||||
@@ -54,6 +55,12 @@ function ReaderUI:init()
|
||||
view = self[1],
|
||||
ui = self
|
||||
}
|
||||
-- Toc menu controller
|
||||
self[5] = ReaderToc:new{
|
||||
dialog = self.dialog,
|
||||
view = self[1],
|
||||
ui = self
|
||||
}
|
||||
-- if needed, insert a paging container
|
||||
if self.document.info.has_pages then
|
||||
local pager = ReaderPaging:new{
|
||||
|
||||
Reference in New Issue
Block a user