mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Menu widget: cleanup (#11759)
This commit is contained in:
@@ -286,8 +286,8 @@ function FileChooser:init()
|
||||
if lfs.attributes(self.path, "mode") ~= "directory" then
|
||||
self.path = G_reader_settings:readSetting("home_dir") or filemanagerutil.getDefaultDir()
|
||||
end
|
||||
self.item_table = self:genItemTableFromPath(self.path)
|
||||
Menu.init(self) -- call parent's init()
|
||||
self:refreshPath()
|
||||
end
|
||||
|
||||
function FileChooser:getList(path, collate)
|
||||
@@ -488,18 +488,17 @@ function FileChooser:getMenuItemMandatory(item, collate)
|
||||
return text
|
||||
end
|
||||
|
||||
function FileChooser:updateItems(select_number)
|
||||
Menu.updateItems(self, select_number) -- call parent's updateItems()
|
||||
function FileChooser:updateItems(select_number, no_recalculate_dimen)
|
||||
Menu.updateItems(self, select_number, no_recalculate_dimen) -- call parent's updateItems()
|
||||
self:mergeTitleBarIntoLayout()
|
||||
self.path_items[self.path] = (self.page - 1) * self.perpage + (select_number or 1)
|
||||
end
|
||||
|
||||
function FileChooser:refreshPath()
|
||||
local itemmatch = nil
|
||||
|
||||
local _, folder_name = util.splitFilePathName(self.path)
|
||||
Screen:setWindowTitle(folder_name)
|
||||
|
||||
local itemmatch
|
||||
if self.focused_path then
|
||||
itemmatch = {path = self.focused_path}
|
||||
-- We use focused_path only once, but remember it
|
||||
@@ -507,8 +506,8 @@ function FileChooser:refreshPath()
|
||||
self.prev_focused_path = self.focused_path
|
||||
self.focused_path = nil
|
||||
end
|
||||
|
||||
self:switchItemTable(nil, self:genItemTableFromPath(self.path), self.path_items[self.path], itemmatch)
|
||||
local subtitle = BD.directory(filemanagerutil.abbreviate(self.path))
|
||||
self:switchItemTable(nil, self:genItemTableFromPath(self.path), self.path_items[self.path], itemmatch, subtitle)
|
||||
end
|
||||
|
||||
function FileChooser:changeToPath(path, focused_path)
|
||||
@@ -646,7 +645,7 @@ function FileChooser:selectAllFilesInFolder(do_select)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end
|
||||
|
||||
return FileChooser
|
||||
|
||||
@@ -13,7 +13,6 @@ local Geom = require("ui/geometry")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local Math = require("optmath")
|
||||
@@ -29,7 +28,6 @@ local Utf8Proc = require("ffi/utf8proc")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
local _ = require("gettext")
|
||||
@@ -89,18 +87,8 @@ end
|
||||
Widget that displays an item for menu
|
||||
--]]
|
||||
local MenuItem = InputContainer:extend{
|
||||
text = nil,
|
||||
bidi_wrap_func = nil,
|
||||
show_parent = nil,
|
||||
detail = nil,
|
||||
font = "cfont",
|
||||
font_size = 24,
|
||||
font = "smallinfofont",
|
||||
infont = "infont",
|
||||
infont_size = 18,
|
||||
dimen = nil,
|
||||
shortcut = nil,
|
||||
shortcut_style = "square",
|
||||
_underline_container = nil,
|
||||
linesize = Size.line.medium,
|
||||
single_line = false,
|
||||
multilines_show_more_text = false,
|
||||
@@ -112,19 +100,19 @@ local MenuItem = InputContainer:extend{
|
||||
|
||||
function MenuItem:init()
|
||||
self.content_width = self.dimen.w - 2 * Size.padding.fullscreen
|
||||
local icon_width = math.floor(self.dimen.h * 4/5)
|
||||
local shortcut_icon_dimen = Geom:new{
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = icon_width,
|
||||
h = icon_width,
|
||||
}
|
||||
|
||||
local shortcut_icon_dimen
|
||||
if self.shortcut then
|
||||
local icon_width = math.floor(self.dimen.h * 4/5)
|
||||
shortcut_icon_dimen = Geom:new{
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = icon_width,
|
||||
h = icon_width,
|
||||
}
|
||||
self.content_width = self.content_width - shortcut_icon_dimen.w - Size.span.horizontal_default
|
||||
end
|
||||
|
||||
self.detail = self.text
|
||||
|
||||
-- we need this table per-instance, so we declare it here
|
||||
self.ges_events = {
|
||||
TapSelect = {
|
||||
@@ -167,9 +155,9 @@ function MenuItem:init()
|
||||
end
|
||||
|
||||
-- State button and indentation for tree expand/collapse (for TOC)
|
||||
local state_button = self.state or HorizontalSpan:new{}
|
||||
local state_indent = self.table.indent or 0
|
||||
local state_width = state_indent + self.state_w
|
||||
local state_button = self.entry.state or HorizontalSpan:new{}
|
||||
local state_indent = self.entry.indent or 0
|
||||
local state_width = state_indent + (self.state_w or 0)
|
||||
local state_container = LeftContainer:new{
|
||||
dimen = Geom:new{w = math.floor(self.content_width / 2), h = self.dimen.h},
|
||||
HorizontalGroup:new{
|
||||
@@ -232,7 +220,9 @@ function MenuItem:init()
|
||||
local dots_widget
|
||||
local dots_left_padding = Size.padding.small
|
||||
local dots_right_padding = Size.padding.small
|
||||
if self.single_line then -- items only in single line
|
||||
|
||||
if self.single_line then
|
||||
-- Items only in single line
|
||||
if self.post_text then
|
||||
post_text_widget = TextWidget:new{
|
||||
text = self.post_text,
|
||||
@@ -377,6 +367,7 @@ function MenuItem:init()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
-- Multi-lines, with fixed user provided font size
|
||||
item_name = TextBoxWidget:new {
|
||||
@@ -482,7 +473,6 @@ function MenuItem:getDotsText(face)
|
||||
}
|
||||
end
|
||||
return _dots_cached_info.text, _dots_cached_info.min_width
|
||||
|
||||
end
|
||||
|
||||
function MenuItem:onFocus(initial_focus)
|
||||
@@ -507,11 +497,6 @@ function MenuItem:onUnfocus()
|
||||
return true
|
||||
end
|
||||
|
||||
function MenuItem:onShowItemDetail()
|
||||
UIManager:show(InfoMessage:new{ text = self.detail, })
|
||||
return true
|
||||
end
|
||||
|
||||
function MenuItem:getGesPosition(ges)
|
||||
local dimen = self[1].dimen
|
||||
return {
|
||||
@@ -526,7 +511,7 @@ function MenuItem:onTapSelect(arg, ges)
|
||||
|
||||
local pos = self:getGesPosition(ges)
|
||||
if G_reader_settings:isFalse("flash_ui") then
|
||||
self.menu:onMenuSelect(self.table, pos)
|
||||
self.menu:onMenuSelect(self.entry, pos)
|
||||
else
|
||||
-- c.f., ui/widget/iconbutton for the canonical documentation about the flash_ui code flow
|
||||
|
||||
@@ -547,7 +532,7 @@ function MenuItem:onTapSelect(arg, ges)
|
||||
|
||||
-- Callback
|
||||
--
|
||||
self.menu:onMenuSelect(self.table, pos)
|
||||
self.menu:onMenuSelect(self.entry, pos)
|
||||
|
||||
UIManager:forceRePaint()
|
||||
end
|
||||
@@ -559,7 +544,7 @@ function MenuItem:onHoldSelect(arg, ges)
|
||||
|
||||
local pos = self:getGesPosition(ges)
|
||||
if G_reader_settings:isFalse("flash_ui") then
|
||||
self.menu:onMenuHold(self.table, pos)
|
||||
self.menu:onMenuHold(self.entry, pos)
|
||||
else
|
||||
-- c.f., ui/widget/iconbutton for the canonical documentation about the flash_ui code flow
|
||||
|
||||
@@ -580,7 +565,7 @@ function MenuItem:onHoldSelect(arg, ges)
|
||||
|
||||
-- Callback
|
||||
--
|
||||
self.menu:onMenuHold(self.table, pos)
|
||||
self.menu:onMenuHold(self.entry, pos)
|
||||
|
||||
UIManager:forceRePaint()
|
||||
end
|
||||
@@ -643,37 +628,37 @@ local Menu = FocusManager:extend{
|
||||
|
||||
function Menu:_recalculateDimen()
|
||||
self.perpage = self.items_per_page or G_reader_settings:readSetting("items_per_page") or self.items_per_page_default
|
||||
self.span_width = 0
|
||||
local height_dim
|
||||
local bottom_height = 0
|
||||
|
||||
local top_height = 0
|
||||
if self.page_return_arrow and self.page_info_text then
|
||||
bottom_height = math.max(self.page_return_arrow:getSize().h, self.page_info_text:getSize().h)
|
||||
+ 2 * Size.padding.button
|
||||
end
|
||||
if self.title_bar and not self.no_title then
|
||||
top_height = self.title_bar:getHeight()
|
||||
if not self.title_bar_fm_style then
|
||||
top_height = top_height + self.header_padding
|
||||
end
|
||||
end
|
||||
height_dim = self.inner_dimen.h - bottom_height - top_height
|
||||
local item_height = math.floor(height_dim / self.perpage)
|
||||
self.span_width = math.floor((height_dim - (self.perpage * item_height)) / 2 - 1)
|
||||
local bottom_height = 0
|
||||
if self.page_return_arrow and self.page_info_text then
|
||||
bottom_height = math.max(self.page_return_arrow:getSize().h, self.page_info_text:getSize().h)
|
||||
+ 2 * Size.padding.button
|
||||
end
|
||||
self.available_height = self.inner_dimen.h - top_height - bottom_height
|
||||
self.item_dimen = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = self.inner_dimen.w,
|
||||
h = item_height,
|
||||
h = math.floor(self.available_height / self.perpage),
|
||||
}
|
||||
self.page_num = math.ceil(#self.item_table / self.perpage)
|
||||
-- fix current page if out of range
|
||||
if self.page_num > 0 and self.page > self.page_num then self.page = self.page_num end
|
||||
|
||||
self.page_num = self:getPageNumber(#self.item_table)
|
||||
if self.page > self.page_num then
|
||||
self.page = self.page_num
|
||||
end
|
||||
end
|
||||
|
||||
function Menu:init()
|
||||
self.show_parent = self.show_parent or self
|
||||
self.item_table = self.item_table or {}
|
||||
self.item_table_stack = {}
|
||||
self.page = 1
|
||||
|
||||
self.screen_w = Screen:getWidth()
|
||||
self.screen_h = Screen:getHeight()
|
||||
@@ -688,20 +673,14 @@ function Menu:init()
|
||||
h = self.dimen.h - 2 * self.border_size,
|
||||
}
|
||||
|
||||
self.page = 1
|
||||
|
||||
self.paths = {} -- per instance table to trace navigation path
|
||||
|
||||
-----------------------------------
|
||||
-- start to set up widget layout --
|
||||
-----------------------------------
|
||||
if self.show_path or not self.no_title then
|
||||
if self.subtitle == nil then
|
||||
if self.show_path then
|
||||
self.subtitle = BD.directory(filemanagerutil.abbreviate(self.path))
|
||||
elseif self.title_bar_fm_style then
|
||||
self.subtitle = ""
|
||||
end
|
||||
if self.subtitle == nil and (self.show_path or self.title_bar_fm_style) then
|
||||
self.subtitle = ""
|
||||
end
|
||||
self.title_bar = TitleBar:new{
|
||||
width = self.dimen.w,
|
||||
@@ -798,7 +777,6 @@ function Menu:init()
|
||||
|
||||
if self.goto_letter then
|
||||
title_goto = _("Enter letter or page number")
|
||||
type_goto = "string"
|
||||
hint_func = function()
|
||||
-- @translators First group is the standard range for alphabetic searches, second group is a page number range
|
||||
return T(_("(a - z) or (1 - %1)"), self.page_num)
|
||||
@@ -822,7 +800,7 @@ function Menu:init()
|
||||
local filename = Utf8Proc.lowercase(util.fixUtf8(FFIUtil.basename(v.path), "?"))
|
||||
local i, _ = filename:find(search_string)
|
||||
if i == 1 and not v.is_go_up then
|
||||
self:onGotoPage(math.ceil(k / self.perpage))
|
||||
self:onGotoPage(self:getPageNumber(k))
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -991,41 +969,11 @@ function Menu:init()
|
||||
self.key_events.Right = { { "Right" } }
|
||||
end
|
||||
|
||||
if #self.item_table > 0 then
|
||||
-- if the table is not yet initialized, this call
|
||||
-- must be done manually:
|
||||
self.page = math.ceil((self.item_table.current or 1) / self.perpage)
|
||||
if self.item_table.current then
|
||||
self.page = self:getPageNumber(self.item_table.current)
|
||||
end
|
||||
if self.path_items then
|
||||
self:refreshPath()
|
||||
else
|
||||
self:updateItems()
|
||||
end
|
||||
end
|
||||
|
||||
function Menu:onShowingReader()
|
||||
-- Clear the dither flag to prevent it from infecting the queue and re-inserting a full-screen refresh...
|
||||
self.dithered = nil
|
||||
end
|
||||
Menu.onSetupShowReader = Menu.onShowingReader
|
||||
|
||||
function Menu:onCloseWidget()
|
||||
--- @fixme
|
||||
-- we cannot refresh regionally using the dimen field
|
||||
-- because some menus without menu title use VerticalGroup to include
|
||||
-- a text widget which is not calculated into the dimen.
|
||||
-- For example, it's a dirty hack to use two menus (one being this menu and
|
||||
-- the other touch menu) in the filemanager in order to capture tap gesture to popup
|
||||
-- the filemanager menu.
|
||||
-- NOTE: For the same reason, don't make it flash,
|
||||
-- because that'll trigger when we close the FM and open a book...
|
||||
|
||||
-- Don't do anything if we're in the process of tearing down FM or RD, or if we don't actually have a live instance of 'em...
|
||||
local FileManager = require("apps/filemanager/filemanager")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
if (FileManager.instance and not FileManager.instance.tearing_down)
|
||||
or (ReaderUI.instance and not ReaderUI.instance.tearing_down) then
|
||||
UIManager:setDirty(nil, "ui")
|
||||
if not self.path_items then -- not FileChooser
|
||||
self:updateItems(1, true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1065,7 +1013,7 @@ function Menu:updatePageInfo(select_number)
|
||||
end
|
||||
end
|
||||
|
||||
function Menu:updateItems(select_number)
|
||||
function Menu:updateItems(select_number, no_recalculate_dimen)
|
||||
local old_dimen = self.dimen and self.dimen:copy()
|
||||
-- self.layout must be updated for focusmanager
|
||||
self.layout = {}
|
||||
@@ -1073,8 +1021,9 @@ function Menu:updateItems(select_number)
|
||||
self.page_info:resetLayout()
|
||||
self.return_button:resetLayout()
|
||||
self.content_group:resetLayout()
|
||||
self:_recalculateDimen()
|
||||
|
||||
if not no_recalculate_dimen then
|
||||
self:_recalculateDimen()
|
||||
end
|
||||
-- default to select the first item
|
||||
if not select_number then
|
||||
select_number = 1
|
||||
@@ -1088,63 +1037,52 @@ function Menu:updateItems(select_number)
|
||||
multilines_show_more_text = G_reader_settings:isTrue("items_multilines_show_more_text")
|
||||
end
|
||||
|
||||
for c = 1, math.min(self.perpage, #self.item_table) do
|
||||
-- calculate index in item_table
|
||||
local i = (self.page - 1) * self.perpage + c
|
||||
if i <= #self.item_table then
|
||||
self.item_table[i].idx = i -- index is valid only for items that have been displayed
|
||||
local item_shortcut = nil
|
||||
local shortcut_style = "square"
|
||||
if self.is_enable_shortcut then
|
||||
-- give different shortcut_style to keys in different
|
||||
-- lines of keyboard
|
||||
if c >= 11 and c <= 20 then
|
||||
--shortcut_style = "rounded_corner"
|
||||
shortcut_style = "grey_square"
|
||||
end
|
||||
item_shortcut = self.item_shortcuts[c]
|
||||
end
|
||||
local item_tmp = MenuItem:new{
|
||||
show_parent = self.show_parent,
|
||||
state = self.item_table[i].state,
|
||||
state_w = self.state_w or 0,
|
||||
text = Menu.getMenuText(self.item_table[i]),
|
||||
bidi_wrap_func = self.item_table[i].bidi_wrap_func,
|
||||
post_text = self.item_table[i].post_text,
|
||||
mandatory = self.item_table[i].mandatory,
|
||||
mandatory_func = self.item_table[i].mandatory_func,
|
||||
mandatory_dim = self.item_table[i].mandatory_dim or self.item_table[i].dim,
|
||||
bold = self.item_table.current == i or self.item_table[i].bold == true,
|
||||
dim = self.item_table[i].dim,
|
||||
font = "smallinfofont",
|
||||
font_size = self.font_size,
|
||||
infont = "infont",
|
||||
infont_size = infont_size,
|
||||
dimen = self.item_dimen:copy(),
|
||||
shortcut = item_shortcut,
|
||||
shortcut_style = shortcut_style,
|
||||
table = self.item_table[i],
|
||||
menu = self,
|
||||
linesize = self.linesize,
|
||||
single_line = self.single_line,
|
||||
multilines_show_more_text = multilines_show_more_text,
|
||||
truncate_left = self.truncate_left,
|
||||
align_baselines = self.align_baselines,
|
||||
with_dots = self.with_dots,
|
||||
line_color = self.line_color,
|
||||
items_padding = self.items_padding,
|
||||
handle_hold_on_hold_release = self.handle_hold_on_hold_release,
|
||||
}
|
||||
table.insert(self.item_group, item_tmp)
|
||||
-- this is for focus manager
|
||||
table.insert(self.layout, {item_tmp})
|
||||
end -- if i <= self.items
|
||||
end -- for c=1, self.perpage
|
||||
local idx_offset = (self.page - 1) * self.perpage
|
||||
for idx = 1, self.perpage do
|
||||
local index = idx_offset + idx
|
||||
local item = self.item_table[index]
|
||||
if item == nil then break end
|
||||
item.idx = index -- index is valid only for items that have been displayed
|
||||
local item_shortcut, shortcut_style
|
||||
if self.is_enable_shortcut then
|
||||
item_shortcut = self.item_shortcuts[idx]
|
||||
-- give different shortcut_style to keys in different lines of keyboard
|
||||
shortcut_style = (idx < 11 or idx > 20) and "square" or "grey_square"
|
||||
end
|
||||
local item_tmp = MenuItem:new{
|
||||
show_parent = self.show_parent,
|
||||
state_w = self.state_w,
|
||||
text = Menu.getMenuText(item),
|
||||
bidi_wrap_func = item.bidi_wrap_func,
|
||||
post_text = item.post_text,
|
||||
mandatory = item.mandatory,
|
||||
mandatory_func = item.mandatory_func,
|
||||
mandatory_dim = item.mandatory_dim or item.dim,
|
||||
bold = self.item_table.current == index or item.bold == true,
|
||||
dim = item.dim,
|
||||
font_size = self.font_size,
|
||||
infont_size = infont_size,
|
||||
dimen = self.item_dimen:copy(),
|
||||
shortcut = item_shortcut,
|
||||
shortcut_style = shortcut_style,
|
||||
entry = item,
|
||||
menu = self,
|
||||
linesize = self.linesize,
|
||||
single_line = self.single_line,
|
||||
multilines_show_more_text = multilines_show_more_text,
|
||||
truncate_left = self.truncate_left,
|
||||
align_baselines = self.align_baselines,
|
||||
with_dots = self.with_dots,
|
||||
line_color = self.line_color,
|
||||
items_padding = self.items_padding,
|
||||
handle_hold_on_hold_release = self.handle_hold_on_hold_release,
|
||||
}
|
||||
table.insert(self.item_group, item_tmp)
|
||||
-- this is for focus manager
|
||||
table.insert(self.layout, {item_tmp})
|
||||
end
|
||||
|
||||
self:updatePageInfo(select_number)
|
||||
if self.show_path then
|
||||
self.title_bar:setSubTitle(BD.directory(filemanagerutil.abbreviate(self.path)))
|
||||
end
|
||||
self:mergeTitleBarIntoLayout()
|
||||
|
||||
UIManager:setDirty(self.show_parent, function()
|
||||
@@ -1174,7 +1112,6 @@ function Menu:mergeTitleBarIntoLayout()
|
||||
self:moveFocusTo(1, menu_item_layout_start_row) -- move focus to first menu item if any, keep original behavior
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
the itemnumber paramter determines menu page number after switching item table
|
||||
1. itemnumber >= 0
|
||||
@@ -1190,6 +1127,10 @@ end
|
||||
which item.key = value
|
||||
--]]
|
||||
function Menu:switchItemTable(new_title, new_item_table, itemnumber, itemmatch, new_subtitle)
|
||||
if new_item_table then
|
||||
self.item_table = new_item_table
|
||||
end
|
||||
|
||||
if self.title_bar then
|
||||
if new_title then
|
||||
self.title_bar:setTitle(new_title, true)
|
||||
@@ -1199,35 +1140,32 @@ function Menu:switchItemTable(new_title, new_item_table, itemnumber, itemmatch,
|
||||
end
|
||||
end
|
||||
|
||||
if itemnumber == nil then
|
||||
self.page = 1
|
||||
elseif itemnumber >= 0 then
|
||||
self.page = math.ceil(itemnumber / self.perpage)
|
||||
end
|
||||
|
||||
if type(itemmatch) == "table" then
|
||||
local key, value = next(itemmatch)
|
||||
for num, item in ipairs(new_item_table) do
|
||||
for num, item in ipairs(self.item_table) do
|
||||
if item[key] == value then
|
||||
self.page = math.floor((num-1) / self.perpage) + 1
|
||||
itemnumber = num
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- make sure current page is in right page range
|
||||
local max_pages = math.ceil(#new_item_table / self.perpage)
|
||||
if self.page > max_pages then
|
||||
self.page = max_pages
|
||||
end
|
||||
if self.page <= 0 then
|
||||
if itemnumber == nil then
|
||||
self.page = 1
|
||||
elseif itemnumber >= 0 then
|
||||
self.page = self:getPageNumber(itemnumber)
|
||||
end
|
||||
|
||||
self.item_table = new_item_table
|
||||
self:updateItems()
|
||||
end
|
||||
|
||||
function Menu:getPageNumber(item_number)
|
||||
if #self.item_table == 0 or item_number == 0 then
|
||||
return 1
|
||||
end
|
||||
return math.ceil(math.min(item_number, #self.item_table) / self.perpage)
|
||||
end
|
||||
|
||||
function Menu:onScreenResize(dimen)
|
||||
self:init()
|
||||
return false
|
||||
@@ -1254,25 +1192,6 @@ function Menu:onShowGotoDialog()
|
||||
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
|
||||
]]--
|
||||
@@ -1318,52 +1237,26 @@ function Menu:onMenuHold(item)
|
||||
end
|
||||
|
||||
function Menu:onNextPage()
|
||||
if self.onNext and self.page == self.page_num - 1 then
|
||||
self:onNext()
|
||||
end
|
||||
if self.page < self.page_num then
|
||||
self.page = self.page + 1
|
||||
self:updateItems()
|
||||
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 == 0 then
|
||||
end_position = self.perpage
|
||||
end
|
||||
if end_position ~= self.selected.y then
|
||||
self:updateItems(end_position)
|
||||
end
|
||||
self.page = 1
|
||||
self:updateItems()
|
||||
end
|
||||
return true
|
||||
local page = self.page < self.page_num and self.page + 1 or 1 -- cycle for swipes only
|
||||
return self:onGotoPage(page)
|
||||
end
|
||||
|
||||
function Menu:onPrevPage()
|
||||
if self.page > 1 then
|
||||
self.page = self.page - 1
|
||||
elseif self.page == 1 then
|
||||
self.page = self.page_num
|
||||
end
|
||||
self:updateItems()
|
||||
return true
|
||||
local page = self.page > 1 and self.page - 1 or self.page_num -- cycle for swipes only
|
||||
return self:onGotoPage(page)
|
||||
end
|
||||
|
||||
function Menu:onFirstPage()
|
||||
self.page = 1
|
||||
self:updateItems()
|
||||
return true
|
||||
return self:onGotoPage(1)
|
||||
end
|
||||
|
||||
function Menu:onLastPage()
|
||||
self.page = self.page_num
|
||||
self:updateItems()
|
||||
return true
|
||||
return self:onGotoPage(self.page_num)
|
||||
end
|
||||
|
||||
function Menu:onGotoPage(page)
|
||||
self.page = page
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -1371,13 +1264,38 @@ function Menu:onRight()
|
||||
return self:sendHoldEventToFocusedWidget()
|
||||
end
|
||||
|
||||
function Menu:onShowingReader()
|
||||
-- Clear the dither flag to prevent it from infecting the queue and re-inserting a full-screen refresh...
|
||||
self.dithered = nil
|
||||
end
|
||||
Menu.onSetupShowReader = Menu.onShowingReader
|
||||
|
||||
function Menu:onCloseWidget()
|
||||
--- @fixme
|
||||
-- we cannot refresh regionally using the dimen field
|
||||
-- because some menus without menu title use VerticalGroup to include
|
||||
-- a text widget which is not calculated into the dimen.
|
||||
-- For example, it's a dirty hack to use two menus (one being this menu and
|
||||
-- the other touch menu) in the filemanager in order to capture tap gesture to popup
|
||||
-- the filemanager menu.
|
||||
-- NOTE: For the same reason, don't make it flash,
|
||||
-- because that'll trigger when we close the FM and open a book...
|
||||
|
||||
-- Don't do anything if we're in the process of tearing down FM or RD, or if we don't actually have a live instance of 'em...
|
||||
local FileManager = require("apps/filemanager/filemanager")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
if (FileManager.instance and not FileManager.instance.tearing_down)
|
||||
or (ReaderUI.instance and not ReaderUI.instance.tearing_down) then
|
||||
UIManager:setDirty(nil, "ui")
|
||||
end
|
||||
end
|
||||
|
||||
function Menu:onClose()
|
||||
local table_length = #self.item_table_stack
|
||||
if table_length == 0 then
|
||||
if #self.item_table_stack == 0 then
|
||||
self:onCloseAllMenus()
|
||||
else
|
||||
-- back to parent menu
|
||||
local parent_item_table = table.remove(self.item_table_stack, table_length)
|
||||
local parent_item_table = table.remove(self.item_table_stack)
|
||||
self:switchItemTable(parent_item_table.title, parent_item_table)
|
||||
end
|
||||
return true
|
||||
@@ -1454,6 +1372,18 @@ end
|
||||
function Menu:onLeftButtonHold() -- to be overriden and implemented by the caller
|
||||
end
|
||||
|
||||
function Menu.getItemFontSize(perpage)
|
||||
-- Get adjusted font size for the given nb of items per page:
|
||||
-- item font size between 14 and 24 for better matching
|
||||
return math.floor(24 - ((perpage - 6) * (1/18)) * 10)
|
||||
end
|
||||
|
||||
function Menu.getItemMandatoryFontSize(perpage)
|
||||
-- Get adjusted font size for the given nb of items per page:
|
||||
-- "mandatory" font size between 12 and 18 for better matching
|
||||
return math.floor(18 - (perpage - 6) * (1/3))
|
||||
end
|
||||
|
||||
--- Adds > to touch menu items with a submenu
|
||||
local arrow_left = "◂" -- U+25C2 BLACK LEFT-POINTING SMALL TRIANGLE
|
||||
local arrow_right = "▸" -- U+25B8 BLACK RIGHT-POINTING SMALL TRIANGLE
|
||||
@@ -1474,18 +1404,6 @@ else
|
||||
end
|
||||
end
|
||||
|
||||
function Menu.getItemFontSize(perpage)
|
||||
-- Get adjusted font size for the given nb of items per page:
|
||||
-- item font size between 14 and 24 for better matching
|
||||
return math.floor(24 - ((perpage - 6) * (1/18)) * 10)
|
||||
end
|
||||
|
||||
function Menu.getItemMandatoryFontSize(perpage)
|
||||
-- Get adjusted font size for the given nb of items per page:
|
||||
-- "mandatory" font size between 12 and 18 for better matching
|
||||
return math.floor(18 - (perpage - 6) * (1/3))
|
||||
end
|
||||
|
||||
function Menu.getMenuText(item)
|
||||
local text
|
||||
if item.text_func then
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
local BD = require("ui/bidi")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local DocSettings = require("docsettings")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
||||
local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
|
||||
@@ -77,7 +75,7 @@ function CoverMenu:updateCache(file, status, do_create, pages)
|
||||
end
|
||||
end
|
||||
|
||||
function CoverMenu:updateItems(select_number)
|
||||
function CoverMenu:updateItems(select_number, no_recalculate_dimen)
|
||||
-- As done in Menu:updateItems()
|
||||
local old_dimen = self.dimen and self.dimen:copy()
|
||||
-- self.layout must be updated for focusmanager
|
||||
@@ -87,7 +85,9 @@ function CoverMenu:updateItems(select_number)
|
||||
-- on the rest of the widget elements being properly laid-out,
|
||||
-- so we have to run it *first*, unlike in Menu.
|
||||
-- Otherwise, various layout issues arise (e.g., MosaicMenu's page_info is misaligned).
|
||||
self:_recalculateDimen()
|
||||
if not no_recalculate_dimen then
|
||||
self:_recalculateDimen()
|
||||
end
|
||||
self.page_info:resetLayout()
|
||||
self.return_button:resetLayout()
|
||||
self.content_group:resetLayout()
|
||||
@@ -145,9 +145,6 @@ function CoverMenu:updateItems(select_number)
|
||||
-- As done in Menu:updateItems()
|
||||
self:updatePageInfo(select_number)
|
||||
|
||||
if self.show_path then
|
||||
self.title_bar:setSubTitle(BD.directory(filemanagerutil.abbreviate(self.path)))
|
||||
end
|
||||
self.show_parent.dithered = self._has_cover_images
|
||||
UIManager:setDirty(self.show_parent, function()
|
||||
local refresh_dimen =
|
||||
@@ -282,7 +279,7 @@ function CoverMenu:updateItems(select_number)
|
||||
["ignore_cover"] = not bookinfo.ignore_cover and 'Y' or false,
|
||||
})
|
||||
UIManager:close(self.file_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{ -- Allow user to ignore some bad metadata (filename will be used instead)
|
||||
@@ -293,7 +290,7 @@ function CoverMenu:updateItems(select_number)
|
||||
["ignore_meta"] = not bookinfo.ignore_meta and 'Y' or false,
|
||||
})
|
||||
UIManager:close(self.file_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
})
|
||||
@@ -305,7 +302,7 @@ function CoverMenu:updateItems(select_number)
|
||||
self:updateCache(file)
|
||||
BookInfoManager:deleteBookInfo(file)
|
||||
UIManager:close(self.file_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
})
|
||||
@@ -360,7 +357,7 @@ function CoverMenu:onHistoryMenuHold(item)
|
||||
["ignore_cover"] = not bookinfo.ignore_cover and 'Y' or false,
|
||||
})
|
||||
UIManager:close(self.histfile_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{ -- Allow user to ignore some bad metadata (filename will be used instead)
|
||||
@@ -371,7 +368,7 @@ function CoverMenu:onHistoryMenuHold(item)
|
||||
["ignore_meta"] = not bookinfo.ignore_meta and 'Y' or false,
|
||||
})
|
||||
UIManager:close(self.histfile_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
})
|
||||
@@ -383,7 +380,7 @@ function CoverMenu:onHistoryMenuHold(item)
|
||||
self:updateCache(file)
|
||||
BookInfoManager:deleteBookInfo(file)
|
||||
UIManager:close(self.histfile_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
})
|
||||
@@ -431,7 +428,7 @@ function CoverMenu:onCollectionsMenuHold(item)
|
||||
["ignore_cover"] = not bookinfo.ignore_cover and 'Y' or false,
|
||||
})
|
||||
UIManager:close(self.collfile_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{ -- Allow user to ignore some bad metadata (filename will be used instead)
|
||||
@@ -442,7 +439,7 @@ function CoverMenu:onCollectionsMenuHold(item)
|
||||
["ignore_meta"] = not bookinfo.ignore_meta and 'Y' or false,
|
||||
})
|
||||
UIManager:close(self.collfile_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
})
|
||||
@@ -454,7 +451,7 @@ function CoverMenu:onCollectionsMenuHold(item)
|
||||
self:updateCache(file)
|
||||
BookInfoManager:deleteBookInfo(file)
|
||||
UIManager:close(self.collfile_dialog)
|
||||
self:updateItems()
|
||||
self:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -11,7 +11,6 @@ local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||
local IconWidget = require("ui/widget/iconwidget")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local LineWidget = require("ui/widget/linewidget")
|
||||
@@ -21,7 +20,6 @@ local RightContainer = require("ui/widget/container/rightcontainer")
|
||||
local Size = require("ui/size")
|
||||
local TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local UnderlineContainer = require("ui/widget/container/underlinecontainer")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
@@ -98,7 +96,6 @@ local ListMenuItem = InputContainer:extend{
|
||||
entry = nil, -- hash, mandatory
|
||||
text = nil,
|
||||
show_parent = nil,
|
||||
detail = nil,
|
||||
dimen = nil,
|
||||
shortcut = nil,
|
||||
shortcut_style = "square",
|
||||
@@ -136,7 +133,6 @@ function ListMenuItem:init()
|
||||
style = self.shortcut_style,
|
||||
}
|
||||
end
|
||||
self.detail = self.text
|
||||
|
||||
-- we need this table per-instance, so we declare it here
|
||||
self.ges_events = {
|
||||
@@ -875,11 +871,6 @@ function ListMenuItem:onUnfocus()
|
||||
return true
|
||||
end
|
||||
|
||||
function ListMenuItem:onShowItemDetail()
|
||||
UIManager:show(InfoMessage:new{ text = self.detail, })
|
||||
return true
|
||||
end
|
||||
|
||||
-- The transient color inversions done in MenuItem:onTapSelect
|
||||
-- and MenuItem:onHoldSelect are ugly when done on an image,
|
||||
-- so let's not do it
|
||||
@@ -992,19 +983,15 @@ function ListMenu:_updateItemsBuildUI()
|
||||
table.insert(self.item_group, line_widget)
|
||||
local idx_offset = (self.page - 1) * self.perpage
|
||||
for idx = 1, self.perpage do
|
||||
local entry = self.item_table[idx_offset + idx]
|
||||
local index = idx_offset + idx
|
||||
local entry = self.item_table[index]
|
||||
if entry == nil then break end
|
||||
|
||||
entry.idx = index
|
||||
-- Keyboard shortcuts, as done in Menu
|
||||
local item_shortcut = nil
|
||||
local shortcut_style = "square"
|
||||
local item_shortcut, shortcut_style
|
||||
if self.is_enable_shortcut then
|
||||
-- give different shortcut_style to keys in different
|
||||
-- lines of keyboard
|
||||
if idx >= 11 and idx <= 20 then
|
||||
shortcut_style = "grey_square"
|
||||
end
|
||||
item_shortcut = self.item_shortcuts[idx]
|
||||
shortcut_style = (idx < 11 or idx > 20) and "square" or "grey_square"
|
||||
end
|
||||
|
||||
local item_tmp = ListMenuItem:new{
|
||||
|
||||
@@ -159,18 +159,17 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
-- add Mosaic / Detailed list mode settings to File browser Settings submenu
|
||||
-- next to Classic mode settings
|
||||
if menu_items.filebrowser_settings == nil then return end
|
||||
local fc = self.ui.file_chooser
|
||||
table.insert (menu_items.filebrowser_settings.sub_item_table, 5, {
|
||||
text = _("Mosaic and detailed list settings"),
|
||||
separator = true,
|
||||
sub_item_table = {
|
||||
{
|
||||
text_func = function()
|
||||
local fc = self.ui.file_chooser
|
||||
return T(_("Items per page in portrait mosaic mode: %1 × %2"), fc.nb_cols_portrait, fc.nb_rows_portrait)
|
||||
end,
|
||||
-- Best to not "keep_menu_open = true", to see how this apply on the full view
|
||||
callback = function()
|
||||
local fc = self.ui.file_chooser
|
||||
local nb_cols = fc.nb_cols_portrait
|
||||
local nb_rows = fc.nb_rows_portrait
|
||||
local DoubleSpinWidget = require("/ui/widget/doublespinwidget")
|
||||
@@ -216,11 +215,9 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
},
|
||||
{
|
||||
text_func = function()
|
||||
local fc = self.ui.file_chooser
|
||||
return T(_("Items per page in landscape mosaic mode: %1 × %2"), fc.nb_cols_landscape, fc.nb_rows_landscape)
|
||||
end,
|
||||
callback = function()
|
||||
local fc = self.ui.file_chooser
|
||||
local nb_cols = fc.nb_cols_landscape
|
||||
local nb_rows = fc.nb_rows_landscape
|
||||
local DoubleSpinWidget = require("/ui/widget/doublespinwidget")
|
||||
@@ -266,13 +263,11 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
},
|
||||
{
|
||||
text_func = function()
|
||||
local fc = self.ui.file_chooser
|
||||
-- default files_per_page should be calculated by ListMenu on the first drawing,
|
||||
-- use 10 if ListMenu has not been drawn yet
|
||||
return T(_("Items per page in portrait list mode: %1"), fc.files_per_page or 10)
|
||||
end,
|
||||
callback = function()
|
||||
local fc = self.ui.file_chooser
|
||||
local files_per_page = fc.files_per_page or 10
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local widget = SpinWidget:new{
|
||||
@@ -312,7 +307,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
checked_func = function() return BookInfoManager:getSetting("show_progress_in_mosaic") end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("show_progress_in_mosaic")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
separator = true,
|
||||
},
|
||||
@@ -321,7 +316,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
checked_func = function() return not BookInfoManager:getSetting("hide_page_info") end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("hide_page_info")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -330,7 +325,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
checked_func = function() return BookInfoManager:getSetting("show_pages_read_as_progress") end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("show_pages_read_as_progress")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -339,7 +334,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
checked_func = function() return BookInfoManager:getSetting("show_pages_left_in_progress") end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("show_pages_left_in_progress")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
},
|
||||
@@ -352,7 +347,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
checked_func = function() return not BookInfoManager:getSetting("no_hint_description") end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("no_hint_description")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -360,7 +355,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
checked_func = function() return BookInfoManager:getSetting("history_hint_opened") end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("history_hint_opened")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -368,7 +363,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
checked_func = function() return BookInfoManager:getSetting("collections_hint_opened") end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("collections_hint_opened")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
}
|
||||
}
|
||||
@@ -386,7 +381,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
series_mode = "append_series_to_authors"
|
||||
end
|
||||
BookInfoManager:saveSetting("series_mode", series_mode)
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -399,7 +394,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
series_mode = "append_series_to_title"
|
||||
end
|
||||
BookInfoManager:saveSetting("series_mode", series_mode)
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -412,7 +407,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
series_mode = "series_in_separate_line"
|
||||
end
|
||||
BookInfoManager:saveSetting("series_mode", series_mode)
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
},
|
||||
},
|
||||
@@ -424,7 +419,7 @@ function CoverBrowser:addToMainMenu(menu_items)
|
||||
end,
|
||||
callback = function()
|
||||
BookInfoManager:toggleSetting("hide_file_info")
|
||||
self:refreshFileManagerInstance()
|
||||
fc:updateItems(1, true)
|
||||
end,
|
||||
separator = true,
|
||||
},
|
||||
|
||||
@@ -12,7 +12,6 @@ local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||
local IconWidget = require("ui/widget/iconwidget")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local ProgressWidget = require("ui/widget/progresswidget")
|
||||
@@ -20,7 +19,6 @@ local OverlapGroup = require("ui/widget/overlapgroup")
|
||||
local Size = require("ui/size")
|
||||
local TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local UnderlineContainer = require("ui/widget/container/underlinecontainer")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
@@ -350,7 +348,6 @@ local MosaicMenuItem = InputContainer:extend{
|
||||
entry = nil, -- table, mandatory
|
||||
text = nil,
|
||||
show_parent = nil,
|
||||
detail = nil,
|
||||
dimen = nil,
|
||||
shortcut = nil,
|
||||
shortcut_style = "square",
|
||||
@@ -387,7 +384,6 @@ function MosaicMenuItem:init()
|
||||
}
|
||||
end
|
||||
|
||||
self.detail = self.text
|
||||
self.percent_finished = nil
|
||||
self.status = nil
|
||||
|
||||
@@ -826,11 +822,6 @@ function MosaicMenuItem:onUnfocus()
|
||||
return true
|
||||
end
|
||||
|
||||
function MosaicMenuItem:onShowItemDetail()
|
||||
UIManager:show(InfoMessage:new{ text = self.detail, })
|
||||
return true
|
||||
end
|
||||
|
||||
-- The transient color inversions done in MenuItem:onTapSelect
|
||||
-- and MenuItem:onHoldSelect are ugly when done on an image,
|
||||
-- so let's not do it
|
||||
@@ -937,11 +928,19 @@ end
|
||||
|
||||
function MosaicMenu:_updateItemsBuildUI()
|
||||
-- Build our grid
|
||||
local idx_offset = (self.page - 1) * self.perpage
|
||||
local cur_row = nil
|
||||
local idx_offset = (self.page - 1) * self.perpage
|
||||
for idx = 1, self.perpage do
|
||||
local entry = self.item_table[idx_offset + idx]
|
||||
local index = idx_offset + idx
|
||||
local entry = self.item_table[index]
|
||||
if entry == nil then break end
|
||||
entry.idx = index
|
||||
-- Keyboard shortcuts, as done in Menu
|
||||
local item_shortcut, shortcut_style
|
||||
if self.is_enable_shortcut then
|
||||
item_shortcut = self.item_shortcuts[idx]
|
||||
shortcut_style = (idx < 11 or idx > 20) and "square" or "grey_square"
|
||||
end
|
||||
|
||||
if idx % self.nb_cols == 1 then -- new row
|
||||
table.insert(self.item_group, VerticalSpan:new{ width = self.item_margin })
|
||||
@@ -958,18 +957,6 @@ function MosaicMenu:_updateItemsBuildUI()
|
||||
table.insert(cur_row, HorizontalSpan:new({ width = self.item_margin }))
|
||||
end
|
||||
|
||||
-- Keyboard shortcuts, as done in Menu
|
||||
local item_shortcut = nil
|
||||
local shortcut_style = "square"
|
||||
if self.is_enable_shortcut then
|
||||
-- give different shortcut_style to keys in different
|
||||
-- lines of keyboard
|
||||
if idx >= 11 and idx <= 20 then
|
||||
shortcut_style = "grey_square"
|
||||
end
|
||||
item_shortcut = self.item_shortcuts[idx]
|
||||
end
|
||||
|
||||
local item_tmp = MosaicMenuItem:new{
|
||||
height = self.item_height,
|
||||
width = self.item_width,
|
||||
|
||||
Reference in New Issue
Block a user