From 8a8b993ade17af775c0c677411e8969bd6c59d1a Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 30 Dec 2012 19:13:46 -0500 Subject: [PATCH] add toc menu for touch UI --- frontend/ui/reader/readertoc.lua | 44 ++++++++++++++++++++++++++------ frontend/ui/readerui.lua | 12 ++++----- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/frontend/ui/reader/readertoc.lua b/frontend/ui/reader/readertoc.lua index 9671154c2..355cb61f5 100644 --- a/frontend/ui/reader/readertoc.lua +++ b/frontend/ui/reader/readertoc.lua @@ -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 diff --git a/frontend/ui/readerui.lua b/frontend/ui/readerui.lua index 19d953540..42f903c05 100644 --- a/frontend/ui/readerui.lua +++ b/frontend/ui/readerui.lua @@ -56,18 +56,18 @@ function ReaderUI:init() view = self[1], ui = self } - -- Toc menu controller - self[3] = ReaderToc:new{ - dialog = self.dialog, + -- reader menu controller + self[3] = ReaderMenu:new{ view = self[1], ui = self } - -- reader menu controller - self[4] = ReaderMenu:new{ + self.menu = self[3] -- hold reference to menu widget + -- Toc menu controller + self[4] = ReaderToc:new{ + dialog = self.dialog, 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