small changes to menu and addition of a reader menu

the reader menu is still very bare-bone, I plan to enhance it now.
pull/2/merge
HW 12 years ago
parent 5b4ce0af82
commit 4d3e6af106

@ -58,9 +58,13 @@ function FocusManager:onFocusMove(args)
-- move cyclic in vertical direction
if self.selected.y + dy > #self.layout then
self.selected.y = 1
if not self:onWrapLast() then
break
end
elseif self.selected.y + dy < 1 then
self.selected.y = #self.layout
if not self:onWrapFirst() then
break
end
else
self.selected.y = self.selected.y + dy
end
@ -80,3 +84,12 @@ function FocusManager:onFocusMove(args)
return true
end
function FocusManager:onWrapFirst()
self.selected.y = #self.layout
return true
end
function FocusManager:onWrapLast()
self.selected.y = 1
return true
end

@ -235,11 +235,11 @@ function Menu:init()
if #self.item_table > 0 then
-- if the table is not yet initialized, this call
-- must be done manually:
self:updateItems()
self:updateItems(1)
end
end
function Menu:updateItems()
function Menu:updateItems(select_number)
self.layout = {}
self.item_group:clear()
@ -272,11 +272,11 @@ function Menu:updateItems()
--self.last_shortcut = c
end -- if i <= self.items
end -- for c=1, self.perpage
-- set focus to first menu item
if self.item_group[1] then
self.item_group[1]:onFocus()
-- reset focus manager accordingly
self.selected = { x = 1, y = 1 }
self.selected = { x = 1, y = select_number }
-- set focus to requested menu item
self.item_group[select_number]:onFocus()
-- update page information
self.page_info.text = "page "..self.page.."/"..self.page_num
else
@ -300,6 +300,25 @@ function Menu:onSelectByShortCut(_, keyevent)
return true
end
function Menu:onWrapFirst()
if self.page > 1 then
self.page = self.page - 1
local end_position = self.perpage
if self.page == self.page_num then
end_position = #self.item_table % self.perpage
end
self:updateItems(end_position)
end
return false
end
function Menu:onWrapLast()
if self.page < self.page_num then
self:onNextPage()
end
return false
end
--[[
override this function to process the item selected in a different manner
]]--
@ -319,7 +338,13 @@ end
function Menu:onNextPage()
if self.page < self.page_num then
self.page = self.page + 1
self:updateItems()
self:updateItems(1)
elseif self.page == self.page_num then
-- on the last page, we check if we're on the last item
local end_position = #self.item_table % self.perpage
if end_position ~= self.selected.y then
self:updateItems(end_position)
end
end
return true
end
@ -327,7 +352,7 @@ end
function Menu:onPrevPage()
if self.page > 1 then
self.page = self.page - 1
self:updateItems()
self:updateItems(1)
end
return true
end

@ -0,0 +1,24 @@
ReaderMenu = InputContainer:new{
key_events = {
ShowMenu = { { "Menu" }, doc = "show menu" },
},
}
function ReaderMenu:onShowMenu()
local item_table = {}
table.insert(item_table, {
text = "Return to file browser"
})
local main_menu = Menu:new{
title = "Document menu",
item_table = item_table,
width = 300,
height = #item_table + 3 * 28
}
UIManager:show(main_menu)
return true
end

@ -6,6 +6,7 @@ require "ui/reader/readerrotation"
require "ui/reader/readerpaging"
require "ui/reader/readerrolling"
require "ui/reader/readertoc"
require "ui/reader/readermenu"
--[[
This is an abstraction for a reader interface
@ -50,6 +51,11 @@ function ReaderUI:init()
view = self[1],
ui = self
}
-- reader menu controller
self[4] = ReaderMenu:new{
view = self[1],
ui = self
}
if self.document.info.has_pages then
-- for page specific controller

Loading…
Cancel
Save