mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[UX] Add ToC/Bookmarks settings
- Menu widget: allow specifying the number of items per page and the item font size, so we can use other values than the default File browser ones - Menu: fix setDirty when a border is used - ToC: add item per page and font size settings, make Alternative ToC more visible (was previously available on long-press on Table of contents) - Bookmarks: add item per page, font size, size reduction - Progress bars (Skim widget and footer): allow selecting ToC depths from which ticks are made.
This commit is contained in:
@@ -185,7 +185,6 @@ function FileManager:setupLayout()
|
||||
is_popout = false,
|
||||
is_borderless = true,
|
||||
has_close_button = true,
|
||||
perpage = G_reader_settings:readSetting("items_per_page"),
|
||||
show_unsupported = show_unsupported,
|
||||
file_filter = function(filename)
|
||||
if DocumentRegistry:hasProvider(filename) then
|
||||
|
||||
@@ -170,7 +170,6 @@ function FileSearcher:showSearchResults()
|
||||
show_parent = menu_container,
|
||||
onMenuHold = self.onMenuHold,
|
||||
cface = Font:getFace("smallinfofont"),
|
||||
perpage = G_reader_settings:readSetting("items_per_page") or 14,
|
||||
_manager = self,
|
||||
}
|
||||
table.insert(menu_container, self.search_menu)
|
||||
|
||||
@@ -158,19 +158,22 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
{
|
||||
text = _("Items per page"),
|
||||
help_text = _([[This sets the number of items per page in:
|
||||
- File browser and history in 'classic' display mode
|
||||
- File browser, history and favorites in 'classic' display mode
|
||||
- Search results and folder shortcuts
|
||||
- File and directory selection
|
||||
- Table of contents
|
||||
- Bookmarks list]]),
|
||||
- Calibre and OPDS browsers/search results]]),
|
||||
keep_menu_open = true,
|
||||
callback = function()
|
||||
local Menu = require("ui/widget/menu")
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_items = G_reader_settings:readSetting("items_per_page") or 14
|
||||
local default_perpage = Menu.items_per_page_default
|
||||
local curr_perpage = G_reader_settings:readSetting("items_per_page") or default_perpage
|
||||
local items = SpinWidget:new{
|
||||
width = math.floor(Screen:getWidth() * 0.6),
|
||||
value = curr_items,
|
||||
value = curr_perpage,
|
||||
value_min = 6,
|
||||
value_max = 24,
|
||||
default_value = default_perpage,
|
||||
title_text = _("Items per page"),
|
||||
keep_shown_on_apply = true,
|
||||
callback = function(spin)
|
||||
@@ -185,9 +188,10 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
text = _("Font size"),
|
||||
keep_menu_open = true,
|
||||
callback = function()
|
||||
local Menu = require("ui/widget/menu")
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_items = G_reader_settings:readSetting("items_per_page") or 14
|
||||
local default_font_size = math.floor(24 - ((curr_items - 6)/ 18) * 10 )
|
||||
local curr_perpage = G_reader_settings:readSetting("items_per_page") or Menu.items_per_page_default
|
||||
local default_font_size = Menu.getItemFontSize(curr_perpage)
|
||||
local curr_font_size = G_reader_settings:readSetting("items_font_size") or default_font_size
|
||||
local items_font = SpinWidget:new{
|
||||
width = math.floor(Screen:getWidth() * 0.6),
|
||||
@@ -198,7 +202,14 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
keep_shown_on_apply = true,
|
||||
title_text = _("Maximum font size for item"),
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("items_font_size", spin.value)
|
||||
if spin.value == default_font_size then
|
||||
-- We can't know if the user has set a size or hit "Use default", but
|
||||
-- assume that if it is the default font size, he will prefer to have
|
||||
-- our default font size if he later update per-page
|
||||
G_reader_settings:delSetting("items_font_size")
|
||||
else
|
||||
G_reader_settings:saveSetting("items_font_size", spin.value)
|
||||
end
|
||||
self.ui:onRefresh()
|
||||
end
|
||||
}
|
||||
@@ -213,6 +224,7 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:flipNilOrFalse("items_multilines_show_more_text")
|
||||
self.ui:onRefresh()
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,6 @@ function SetDefaults:init()
|
||||
width = Screen:getWidth()-15,
|
||||
height = Screen:getHeight()-15,
|
||||
cface = Font:getFace("smallinfofont"),
|
||||
perpage = G_reader_settings:readSetting("items_per_page") or 14,
|
||||
show_parent = menu_container,
|
||||
_manager = self,
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ local T = require("ffi/util").template
|
||||
local ReaderBookmark = InputContainer:new{
|
||||
bm_menu_title = _("Bookmarks"),
|
||||
bbm_menu_title = _("Bookmark browsing mode"),
|
||||
bookmarks_items_per_page_default = 14,
|
||||
bookmarks = nil,
|
||||
}
|
||||
|
||||
@@ -30,6 +31,21 @@ function ReaderBookmark:init()
|
||||
doc = "show bookmarks" },
|
||||
}
|
||||
end
|
||||
|
||||
if not G_reader_settings:readSetting("bookmarks_items_per_page") then
|
||||
-- The Bookmarks items per page and items' font size can now be
|
||||
-- configured. Previously, the ones set for the file browser
|
||||
-- were used. Initialize them from these ones.
|
||||
local items_per_page = G_reader_settings:readSetting("items_per_page")
|
||||
or self.bookmarks_items_per_page_default
|
||||
G_reader_settings:saveSetting("bookmarks_items_per_page", items_per_page)
|
||||
local items_font_size = G_reader_settings:readSetting("items_font_size")
|
||||
if items_font_size and items_font_size ~= Menu.getItemFontSize(items_per_page) then
|
||||
-- Keep the user items font size if it's not the default for items_per_page
|
||||
G_reader_settings:saveSetting("bookmarks_items_font_size", items_font_size)
|
||||
end
|
||||
end
|
||||
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
@@ -59,6 +75,58 @@ function ReaderBookmark:addToMainMenu(menu_items)
|
||||
end,
|
||||
}
|
||||
end
|
||||
menu_items.bookmarks_items_per_page = {
|
||||
text = _("Bookmarks per page"),
|
||||
keep_menu_open = true,
|
||||
callback = function()
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_perpage = G_reader_settings:readSetting("bookmarks_items_per_page") or self.bookmarks_items_per_page_default
|
||||
local items = SpinWidget:new{
|
||||
width = math.floor(Screen:getWidth() * 0.6),
|
||||
value = curr_perpage,
|
||||
value_min = 6,
|
||||
value_max = 24,
|
||||
default_value = self.bookmarks_items_per_page_default,
|
||||
title_text = _("Bookmarks per page"),
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("bookmarks_items_per_page", spin.value)
|
||||
end
|
||||
}
|
||||
UIManager:show(items)
|
||||
end
|
||||
}
|
||||
menu_items.bookmarks_items_font_size = {
|
||||
text = _("Bookmark font size"),
|
||||
keep_menu_open = true,
|
||||
callback = function()
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_perpage = G_reader_settings:readSetting("bookmarks_items_per_page") or self.bookmarks_items_per_page_default
|
||||
local default_font_size = Menu.getItemFontSize(curr_perpage)
|
||||
local curr_font_size = G_reader_settings:readSetting("bookmarks_items_font_size") or default_font_size
|
||||
local items_font = SpinWidget:new{
|
||||
width = math.floor(Screen:getWidth() * 0.6),
|
||||
value = curr_font_size,
|
||||
value_min = 10,
|
||||
value_max = 72,
|
||||
default_value = default_font_size,
|
||||
title_text = _("Bookmark font size"),
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("bookmarks_items_font_size", spin.value)
|
||||
end
|
||||
}
|
||||
UIManager:show(items_font)
|
||||
end,
|
||||
}
|
||||
menu_items.bookmarks_items_show_more_text = {
|
||||
text = _("Shrink bookmark font size to fit more text"),
|
||||
keep_menu_open = true,
|
||||
checked_func = function()
|
||||
return G_reader_settings:isTrue("bookmarks_items_multilines_show_more_text")
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:flipNilOrFalse("bookmarks_items_multilines_show_more_text")
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
function ReaderBookmark:enableBookmarkBrowsingMode()
|
||||
@@ -271,6 +339,10 @@ function ReaderBookmark:onShowBookmark()
|
||||
end
|
||||
end
|
||||
|
||||
local items_per_page = G_reader_settings:readSetting("bookmarks_items_per_page") or self.bookmarks_items_per_page_default
|
||||
local items_font_size = G_reader_settings:readSetting("bookmarks_items_font_size") or Menu.getItemFontSize(items_per_page)
|
||||
local multilines_show_more_text = G_reader_settings:isTrue("bookmarks_items_multilines_show_more_text")
|
||||
|
||||
local bm_menu = Menu:new{
|
||||
title = _("Bookmarks"),
|
||||
item_table = self.bookmarks,
|
||||
@@ -279,7 +351,9 @@ function ReaderBookmark:onShowBookmark()
|
||||
width = Screen:getWidth(),
|
||||
height = Screen:getHeight(),
|
||||
cface = Font:getFace("x_smallinfofont"),
|
||||
perpage = G_reader_settings:readSetting("items_per_page") or 14,
|
||||
items_per_page = items_per_page,
|
||||
items_font_size = items_font_size,
|
||||
multilines_show_more_text = multilines_show_more_text,
|
||||
line_color = require("ffi/blitbuffer").COLOR_WHITE,
|
||||
on_close_ges = {
|
||||
GestureRange:new{
|
||||
|
||||
@@ -169,12 +169,13 @@ function ReaderFont:onShowFontMenu()
|
||||
width = Screen:getWidth() - 100,
|
||||
height = math.floor(Screen:getHeight() * 0.5),
|
||||
single_line = true,
|
||||
perpage_custom = 8,
|
||||
items_per_page = 8,
|
||||
items_font_size = Menu.getItemFontSize(8),
|
||||
}
|
||||
-- build container
|
||||
local menu_container = CenterContainer:new{
|
||||
main_menu,
|
||||
dimen = Screen:getSize(),
|
||||
main_menu,
|
||||
}
|
||||
main_menu.close_callback = function ()
|
||||
UIManager:close(menu_container)
|
||||
|
||||
@@ -207,6 +207,10 @@ function ReaderPageMap:onShowPageList()
|
||||
page_list.current = cur_page_idx
|
||||
end
|
||||
|
||||
-- We use the per-page and font-size settings set for the ToC
|
||||
local items_per_page = G_reader_settings:readSetting("toc_items_per_page") or 14
|
||||
local items_font_size = G_reader_settings:readSetting("toc_items_font_size") or Menu.getItemFontSize(items_per_page)
|
||||
|
||||
local pl_menu = Menu:new{
|
||||
title = _("Reference page numbers list"),
|
||||
item_table = page_list,
|
||||
@@ -215,7 +219,8 @@ function ReaderPageMap:onShowPageList()
|
||||
width = Screen:getWidth(),
|
||||
height = Screen:getHeight(),
|
||||
cface = Font:getFace("x_smallinfofont"),
|
||||
perpage = G_reader_settings:readSetting("items_per_page") or 14,
|
||||
items_per_page = items_per_page,
|
||||
items_font_size = items_font_size,
|
||||
line_color = require("ffi/blitbuffer").COLOR_WHITE,
|
||||
single_line = true,
|
||||
on_close_ges = {
|
||||
|
||||
@@ -859,7 +859,7 @@ function ReaderRolling:updatePos()
|
||||
self:_gotoXPointer(self.xpointer)
|
||||
self.ui:handleEvent(Event:new("UpdateToc"))
|
||||
end
|
||||
self:updateTopStatusBarMarkers()
|
||||
self:onUpdateTopStatusBarMarkers()
|
||||
UIManager:setDirty(self.view.dialog, "partial")
|
||||
-- Allow for the new rendering to be shown before possibly showing
|
||||
-- the "Styles have changed..." ConfirmBox so the user can decide
|
||||
@@ -1042,7 +1042,7 @@ function ReaderRolling:onSetStatusLine(status_line)
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
end
|
||||
|
||||
function ReaderRolling:updateTopStatusBarMarkers()
|
||||
function ReaderRolling:onUpdateTopStatusBarMarkers()
|
||||
if not self.cre_top_bar_enabled then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -28,6 +28,7 @@ local ReaderToc = InputContainer:new{
|
||||
expanded_nodes = {},
|
||||
toc_menu_title = _("Table of contents"),
|
||||
alt_toc_menu_title = _("Table of contents *"),
|
||||
toc_items_per_page_default = 14,
|
||||
}
|
||||
|
||||
function ReaderToc:init()
|
||||
@@ -38,10 +39,33 @@ function ReaderToc:init()
|
||||
doc = "show Table of Content menu" },
|
||||
}
|
||||
end
|
||||
|
||||
if not G_reader_settings:readSetting("toc_items_per_page") then
|
||||
-- The TOC items per page and items' font size can now be
|
||||
-- configured. Previously, the ones set for the file browser
|
||||
-- were used. Initialize them from these ones.
|
||||
local items_per_page = G_reader_settings:readSetting("items_per_page")
|
||||
or self.toc_items_per_page_default
|
||||
G_reader_settings:saveSetting("toc_items_per_page", items_per_page)
|
||||
local items_font_size = G_reader_settings:readSetting("items_font_size")
|
||||
if items_font_size and items_font_size ~= Menu.getItemFontSize(items_per_page) then
|
||||
-- Keep the user items font size if it's not the default for items_per_page
|
||||
G_reader_settings:saveSetting("toc_items_font_size", items_font_size)
|
||||
end
|
||||
end
|
||||
|
||||
self:resetToc()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
function ReaderToc:onReadSettings(config)
|
||||
self.toc_ticks_ignored_levels = config:readSetting("toc_ticks_ignored_levels") or {}
|
||||
end
|
||||
|
||||
function ReaderToc:onSaveSettings()
|
||||
self.ui.doc_settings:saveSetting("toc_ticks_ignored_levels", self.toc_ticks_ignored_levels)
|
||||
end
|
||||
|
||||
function ReaderToc:cleanUpTocTitle(title, replace_empty)
|
||||
title = title:gsub("\13", "")
|
||||
if replace_empty and title:match("^%s*$") then
|
||||
@@ -380,11 +404,13 @@ function ReaderToc:getTocTicksFlattened()
|
||||
|
||||
-- Keep track of what we add to avoid duplicates (c.f., https://stackoverflow.com/a/20067270)
|
||||
local hash = {}
|
||||
for _, v in ipairs(ticks) do
|
||||
for depth, page in ipairs(v) do
|
||||
if not hash[page] then
|
||||
table.insert(ticks_flattened, page)
|
||||
hash[page] = true
|
||||
for depth, v in ipairs(ticks) do
|
||||
if not self.toc_ticks_ignored_levels[depth] then
|
||||
for _, page in ipairs(v) do
|
||||
if not hash[page] then
|
||||
table.insert(ticks_flattened, page)
|
||||
hash[page] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -571,8 +597,9 @@ function ReaderToc:onShowToc()
|
||||
end
|
||||
end
|
||||
|
||||
local items_per_page = G_reader_settings:readSetting("toc_items_per_page") or self.toc_items_per_page_default
|
||||
local items_font_size = G_reader_settings:readSetting("toc_items_font_size") or Menu.getItemFontSize(items_per_page)
|
||||
-- Estimate expand/collapse icon size
|
||||
local items_per_page = G_reader_settings:readSetting("items_per_page") or 14
|
||||
-- *2/5 to acount for Menu top title and bottom icons, and add some air between consecutive icons
|
||||
local icon_size = math.floor(Screen:getHeight() / items_per_page * 2/5)
|
||||
local button_width = icon_size * 2
|
||||
@@ -627,7 +654,8 @@ function ReaderToc:onShowToc()
|
||||
cface = Font:getFace("x_smallinfofont"),
|
||||
single_line = true,
|
||||
align_baselines = true,
|
||||
perpage = items_per_page,
|
||||
items_per_page = items_per_page,
|
||||
items_font_size = items_font_size,
|
||||
line_color = require("ffi/blitbuffer").COLOR_WHITE,
|
||||
on_close_ges = {
|
||||
GestureRange:new{
|
||||
@@ -785,38 +813,157 @@ function ReaderToc:addToMainMenu(menu_items)
|
||||
self:onShowToc()
|
||||
end,
|
||||
}
|
||||
-- ToC (and other navigation) settings
|
||||
menu_items.navi_settings = {
|
||||
text = _("Settings"),
|
||||
}
|
||||
-- Alternative ToC (only available with CRE documents)
|
||||
if self.ui.document:canHaveAlternativeToc() then
|
||||
menu_items.table_of_contents.hold_callback = function(touchmenu_instance)
|
||||
if self.ui.document:isTocAlternativeToc() then
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("The table of content for this book is currently an alternative one built from the document headings.\nDo you want to get back the original table of content? (The book will be reloaded.)"),
|
||||
ok_callback = function()
|
||||
touchmenu_instance:closeMenu()
|
||||
self.ui.doc_settings:delSetting("alternative_toc")
|
||||
self.ui.document:invalidateCacheFile()
|
||||
-- Allow for ConfirmBox to be closed before showing
|
||||
-- "Opening file" InfoMessage
|
||||
UIManager:scheduleIn(0.5, function ()
|
||||
self.ui:reloadDocument()
|
||||
end)
|
||||
end,
|
||||
})
|
||||
else
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Do you want to use an alternative table of content built from the document headings?"),
|
||||
ok_callback = function()
|
||||
touchmenu_instance:closeMenu()
|
||||
self:resetToc()
|
||||
self.ui.document:buildAlternativeToc()
|
||||
self.ui.doc_settings:saveSetting("alternative_toc", true)
|
||||
self:onShowToc()
|
||||
self.view.footer:setTocMarkers(true)
|
||||
self.view.footer:onUpdateFooter()
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
menu_items.toc_alt_toc = {
|
||||
text = _("Alternative table of contents"),
|
||||
help_text = _([[
|
||||
An alternative table of contents can be built from document headings <H1> to <H6>.
|
||||
If the document contains no headings, or all are ignored, the alternative ToC will be built from document fragments and will point to the start of each individual HTML file in the EPUB.
|
||||
|
||||
Some of the headings can be ignored, and hints can be set to other non-heading elements in a user style tweak, so they can be used as ToC items.
|
||||
See Style tweaks → Miscellaneous → Alternative ToC hints.]]),
|
||||
checked_func = function()
|
||||
return self.ui.document:isTocAlternativeToc()
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
if self.ui.document:isTocAlternativeToc() then
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("The table of contents for this book is currently an alternative one built from the document headings.\nDo you want to get back the original table of contents? (The book will be reloaded.)"),
|
||||
ok_callback = function()
|
||||
touchmenu_instance:closeMenu()
|
||||
self.ui.doc_settings:delSetting("alternative_toc")
|
||||
self.ui.document:invalidateCacheFile()
|
||||
self.toc_ticks_ignored_levels = {} -- reset this
|
||||
-- Allow for ConfirmBox to be closed before showing
|
||||
-- "Opening file" InfoMessage
|
||||
UIManager:scheduleIn(0.5, function ()
|
||||
self.ui:reloadDocument()
|
||||
end)
|
||||
end,
|
||||
})
|
||||
else
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Do you want to use an alternative table of contents built from the document headings?"),
|
||||
ok_callback = function()
|
||||
touchmenu_instance:closeMenu()
|
||||
self:resetToc()
|
||||
self.toc_ticks_ignored_levels = {} -- reset this
|
||||
self.ui.document:buildAlternativeToc()
|
||||
self.ui.doc_settings:saveSetting("alternative_toc", true)
|
||||
self:onShowToc()
|
||||
self.view.footer:setTocMarkers(true)
|
||||
self.view.footer:onUpdateFooter()
|
||||
self.ui:handleEvent(Event:new("UpdateTopStatusBarMarkers"))
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
||||
-- Allow to have getTocTicksFlattened() get rid of all items at some depths, which
|
||||
-- might be useful to have the footer and SkimTo progress bar less crowded.
|
||||
-- This also affects the footer current chapter title, but leave the ToC itself unchanged.
|
||||
local genTocLevelIgnoreMenuItem = function(level)
|
||||
if not self.ticks or not self.ticks[level] then
|
||||
return
|
||||
end
|
||||
return {
|
||||
text_func = function()
|
||||
return T(_("%1 entries at ToC depth %2"), #self.ticks[level], level)
|
||||
end,
|
||||
checked_func = function()
|
||||
return not self.toc_ticks_ignored_levels[level]
|
||||
end,
|
||||
callback = function()
|
||||
self.toc_ticks_ignored_levels[level] = not self.toc_ticks_ignored_levels[level]
|
||||
self:onUpdateToc()
|
||||
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
||||
self.ui:handleEvent(Event:new("UpdateTopStatusBarMarkers"))
|
||||
end,
|
||||
}
|
||||
end
|
||||
menu_items.toc_ticks_level_ignore = {
|
||||
text_func = function()
|
||||
local nb_ticks = 0
|
||||
if self.ticks then
|
||||
for level=1, #self.ticks do
|
||||
if not self.toc_ticks_ignored_levels[level] then
|
||||
nb_ticks = nb_ticks + #self.ticks[level]
|
||||
end
|
||||
end
|
||||
end
|
||||
return T(_("Progress bars: %1 ticks"), nb_ticks)
|
||||
end,
|
||||
help_text = _([[The progress bars in the footer and the skim dialog can become cramped when the table of contents is complex. This allows you to restrict the number of tick marks.]]),
|
||||
enabled_func = function()
|
||||
return self.ticks and #self.ticks > 0
|
||||
end,
|
||||
sub_item_table_func = function()
|
||||
local toc_ticks_levels = {}
|
||||
local level = 1
|
||||
while true do
|
||||
local item = genTocLevelIgnoreMenuItem(level)
|
||||
if item then
|
||||
table.insert(toc_ticks_levels, item)
|
||||
level = level + 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
return toc_ticks_levels
|
||||
end,
|
||||
}
|
||||
menu_items.toc_items_per_page = {
|
||||
text = _("ToC entries per page"),
|
||||
keep_menu_open = true,
|
||||
callback = function()
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_perpage = G_reader_settings:readSetting("toc_items_per_page") or self.toc_items_per_page_default
|
||||
local items = SpinWidget:new{
|
||||
width = math.floor(Screen:getWidth() * 0.6),
|
||||
value = curr_perpage,
|
||||
value_min = 6,
|
||||
value_max = 24,
|
||||
default_value = self.toc_items_per_page_default,
|
||||
title_text = _("ToC entries per page"),
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("toc_items_per_page", spin.value)
|
||||
-- We need to reset the TOC so cached expand/collapsed icons
|
||||
-- instances (as item.state), which were sized for a previous
|
||||
-- value or items_per_page, are forgotten.
|
||||
self:resetToc()
|
||||
end
|
||||
}
|
||||
UIManager:show(items)
|
||||
end
|
||||
}
|
||||
menu_items.toc_items_font_size = {
|
||||
text = _("ToC entry font size"),
|
||||
keep_menu_open = true,
|
||||
callback = function()
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_perpage = G_reader_settings:readSetting("toc_items_per_page") or self.toc_items_per_page_default
|
||||
local default_font_size = Menu.getItemFontSize(curr_perpage)
|
||||
local curr_font_size = G_reader_settings:readSetting("toc_items_font_size") or default_font_size
|
||||
local items_font = SpinWidget:new{
|
||||
width = math.floor(Screen:getWidth() * 0.6),
|
||||
value = curr_font_size,
|
||||
value_min = 10,
|
||||
value_max = 72,
|
||||
default_value = default_font_size,
|
||||
title_text = _("ToC entry font size"),
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("toc_items_font_size", spin.value)
|
||||
end
|
||||
}
|
||||
UIManager:show(items_font)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
return ReaderToc
|
||||
|
||||
@@ -577,18 +577,18 @@ width: 100% !important;
|
||||
{
|
||||
title = _("Miscellaneous"),
|
||||
{
|
||||
title = _("Alternative TOC hints"),
|
||||
title = _("Alternative ToC hints"),
|
||||
{
|
||||
title = _("About alternative TOC"),
|
||||
title = _("About alternative ToC"),
|
||||
info_text = _([[
|
||||
An alternative table of contents can be built with a long-press on the "Table of contents" menu item.
|
||||
An alternative table of contents can be built from the "Table of contents" settings menu.
|
||||
|
||||
The TOC will be built from document headings <H1> to <H6>. Some of these can be ignored with the tweaks available here.
|
||||
If the document contains no headings, or all are ignored, the alternative TOC will be built from document fragments and will point to the start of each individual HTML file in the EPUB.
|
||||
The ToC will be built from document headings <H1> to <H6>. Some of these can be ignored with the tweaks available here.
|
||||
If the document contains no headings, or all are ignored, the alternative ToC will be built from document fragments and will point to the start of each individual HTML file in the EPUB.
|
||||
|
||||
Hints can be set to other non-heading elements in a user style tweak, so they can be used as TOC items. Since this would be quite book-specific, please see the final tweak for some examples.
|
||||
Hints can be set to other non-heading elements in a user style tweak, so they can be used as ToC items. Since this would be quite book-specific, please see the final tweak for some examples.
|
||||
|
||||
After applying these tweaks, the alternative TOC needs to be rebuilt by long-pressing "Table of contents" twice: once to restore the original TOC, and once to build the alternative TOC again.]]),
|
||||
After applying these tweaks, the alternative ToC needs to be rebuilt by toggling it twice in its menu: once to restore the original ToC, and once to build the alternative ToC again.]]),
|
||||
separator = true,
|
||||
},
|
||||
{
|
||||
@@ -629,9 +629,9 @@ After applying these tweaks, the alternative TOC needs to be rebuilt by long-pre
|
||||
},
|
||||
{
|
||||
id = "alt_toc_level_example";
|
||||
title = _("Example of book specific TOC hints"),
|
||||
title = _("Example of book specific ToC hints"),
|
||||
description = _([[
|
||||
If headings or document fragments do not result in a usable TOC, you can inspect the HTML and look for elements that contain chapter titles. Then you can set hints to their class names.
|
||||
If headings or document fragments do not result in a usable ToC, you can inspect the HTML and look for elements that contain chapter titles. Then you can set hints to their class names.
|
||||
This is just an example, that will need to be adapted into a user style tweak.]]),
|
||||
css = [[
|
||||
.book_n { -cr-hint: toc-level1; }
|
||||
|
||||
@@ -15,6 +15,8 @@ local order = {
|
||||
"bookmarks",
|
||||
"toggle_bookmark",
|
||||
"bookmark_browsing_mode",
|
||||
"navi_settings",
|
||||
"----------------------------",
|
||||
"page_map",
|
||||
"hide_nonlinear_flows",
|
||||
"----------------------------",
|
||||
@@ -24,6 +26,18 @@ local order = {
|
||||
"----------------------------",
|
||||
"go_to_previous_location",
|
||||
},
|
||||
navi_settings = {
|
||||
"toc_alt_toc",
|
||||
"----------------------------",
|
||||
"toc_ticks_level_ignore",
|
||||
"----------------------------",
|
||||
"toc_items_per_page",
|
||||
"toc_items_font_size",
|
||||
"----------------------------",
|
||||
"bookmarks_items_per_page",
|
||||
"bookmarks_items_font_size",
|
||||
"bookmarks_items_show_more_text",
|
||||
},
|
||||
typeset = {
|
||||
"set_render_style",
|
||||
"style_tweaks",
|
||||
|
||||
@@ -29,7 +29,6 @@ local FileChooser = Menu:extend{
|
||||
collate = "strcoll", -- or collate = "access",
|
||||
reverse_collate = false,
|
||||
path_items = {}, -- store last browsed location(item index) for each path
|
||||
perpage = G_reader_settings:readSetting("items_per_page"),
|
||||
goto_letter = true,
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ local MenuItem = InputContainer:new{
|
||||
_underline_container = nil,
|
||||
linesize = Size.line.medium,
|
||||
single_line = false,
|
||||
multilines_show_more_text = false,
|
||||
-- Align text & mandatory baselines (only when single_line=true)
|
||||
align_baselines = false,
|
||||
}
|
||||
@@ -193,8 +194,7 @@ function MenuItem:init()
|
||||
if self.infont_size > max_font_size then
|
||||
self.infont_size = max_font_size
|
||||
end
|
||||
local multilines_show_more_text = G_reader_settings:isTrue("items_multilines_show_more_text")
|
||||
if not self.single_line and not multilines_show_more_text then
|
||||
if not self.single_line and not self.multilines_show_more_text then
|
||||
-- For non single line menus (File browser, Bookmarks), if the
|
||||
-- user provided font size is large and would not allow showing
|
||||
-- more than one line in our item height, just switch to single
|
||||
@@ -297,7 +297,7 @@ function MenuItem:init()
|
||||
end
|
||||
end
|
||||
|
||||
elseif multilines_show_more_text then
|
||||
elseif self.multilines_show_more_text then
|
||||
-- Multi-lines, with font size decrease if needed to show more of the text.
|
||||
-- It would be costly/slow with use_xtext if we were to try all
|
||||
-- font sizes from self.font_size to min_font_size (12).
|
||||
@@ -581,14 +581,6 @@ Widget that displays menu
|
||||
--]]
|
||||
local Menu = FocusManager:new{
|
||||
show_parent = nil,
|
||||
-- face for displaying item contents
|
||||
cface = Font:getFace("cfont"),
|
||||
-- face for menu title
|
||||
tface = Font:getFace("tfont"),
|
||||
-- face for paging info display
|
||||
fface = Font:getFace("ffont"),
|
||||
-- font for item shortcut
|
||||
sface = Font:getFace("scfont"),
|
||||
|
||||
title = "No Title",
|
||||
-- default width and height
|
||||
@@ -613,6 +605,13 @@ local Menu = FocusManager:new{
|
||||
page_info = nil,
|
||||
page_return = nil,
|
||||
|
||||
items_per_page_default = 14,
|
||||
items_per_page = nil,
|
||||
items_font_size = nil,
|
||||
items_mandatory_font_size = nil,
|
||||
multilines_show_more_text = nil,
|
||||
-- Global settings or default values will be used if not provided
|
||||
|
||||
-- set this to true to not paint as popup menu
|
||||
is_borderless = false,
|
||||
-- if you want to embed the menu widget into another widget, set
|
||||
@@ -624,12 +623,11 @@ local Menu = FocusManager:new{
|
||||
-- it is usually set by the widget which creates the menu
|
||||
close_callback = nil,
|
||||
linesize = Size.line.medium,
|
||||
perpage = G_reader_settings:readSetting("items_per_page") or 14,
|
||||
line_color = Blitbuffer.COLOR_DARK_GRAY,
|
||||
}
|
||||
|
||||
function Menu:_recalculateDimen()
|
||||
self.perpage = self.perpage_custom or G_reader_settings:readSetting("items_per_page") or 14
|
||||
self.perpage = self.items_per_page or G_reader_settings:readSetting("items_per_page") or self.items_per_page_default
|
||||
self.span_width = 0
|
||||
self.dimen.w = self.width
|
||||
self.dimen.h = self.height or Screen:getHeight()
|
||||
@@ -676,7 +674,7 @@ function Menu:init()
|
||||
self.menu_title = TextWidget:new{
|
||||
overlap_align = "center",
|
||||
text = self.title,
|
||||
face = self.tface,
|
||||
face = Font:getFace("tfont"),
|
||||
}
|
||||
local menu_title_container = CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
@@ -906,7 +904,7 @@ function Menu:init()
|
||||
|
||||
self[1] = FrameContainer:new{
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
bordersize = self.is_borderless and 0 or 2,
|
||||
bordersize = self.is_borderless and 0 or Size.border.window,
|
||||
padding = 0,
|
||||
margin = 0,
|
||||
radius = self.is_popout and math.floor(self.dimen.w/20) or 0,
|
||||
@@ -1049,10 +1047,14 @@ function Menu:updateItems(select_number)
|
||||
if not select_number then
|
||||
select_number = 1
|
||||
end
|
||||
--font size between 12 and 18 for better matching
|
||||
local infont_size = math.floor(18 - (self.perpage - 6) / 3)
|
||||
--default font size between 14 and 24 for better matching
|
||||
local font_size = G_reader_settings:readSetting("items_font_size") or math.floor(24 - ((self.perpage - 6)/ 18) * 10 )
|
||||
|
||||
local font_size = self.items_font_size or G_reader_settings:readSetting("items_font_size")
|
||||
or Menu.getItemFontSize(self.perpage)
|
||||
local infont_size = self.items_mandatory_font_size or Menu.getItemMandatoryFontSize(self.perpage)
|
||||
local multilines_show_more_text = self.multilines_show_more_text
|
||||
if multilines_show_more_text == nil then
|
||||
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
|
||||
@@ -1090,6 +1092,7 @@ function Menu:updateItems(select_number)
|
||||
menu = self,
|
||||
linesize = self.linesize,
|
||||
single_line = self.single_line,
|
||||
multilines_show_more_text = multilines_show_more_text,
|
||||
align_baselines = self.align_baselines,
|
||||
line_color = self.line_color,
|
||||
}
|
||||
@@ -1108,6 +1111,12 @@ function Menu:updateItems(select_number)
|
||||
local refresh_dimen =
|
||||
old_dimen and old_dimen:combine(self.dimen)
|
||||
or self.dimen
|
||||
if not self.is_borderless then
|
||||
refresh_dimen = refresh_dimen:copy()
|
||||
local bordersize = Size.border.window
|
||||
refresh_dimen.w = refresh_dimen.w + bordersize*2
|
||||
refresh_dimen.h = refresh_dimen.h + bordersize*2
|
||||
end
|
||||
return "ui", refresh_dimen
|
||||
end)
|
||||
end
|
||||
@@ -1375,6 +1384,18 @@ 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)/ 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) / 3)
|
||||
end
|
||||
|
||||
function Menu.getMenuText(item)
|
||||
local text
|
||||
if item.text_func then
|
||||
|
||||
Reference in New Issue
Block a user