mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
BookMap: add option Alternative theme
When enabled in BookMap, both BookMap and PageBrowser get: - alternating gray background on chapter spans - hatched background instead of uni-gray on hidden flows. Also, with both normal look and this alternative theme, show some hatched overlay on thumbnails part of hidden flows. ReaderToc: for each TOC item, have it carry its sequence/number in that level (we do this in validateAndFixToc() where we are already iterating all the items).
This commit is contained in:
@@ -180,8 +180,10 @@ function ReaderToc:validateAndFixToc()
|
||||
local has_bogus
|
||||
local cur_page = 0
|
||||
local max_depth = 0
|
||||
local cur_seq_by_level = {}
|
||||
for i = first, last do
|
||||
local page = toc[i].page
|
||||
local item = toc[i]
|
||||
local page = item.page
|
||||
if page < cur_page then
|
||||
has_bogus = true
|
||||
break
|
||||
@@ -189,9 +191,15 @@ function ReaderToc:validateAndFixToc()
|
||||
cur_page = page
|
||||
-- Use this loop to compute max_depth here (if has_bogus,
|
||||
-- we will recompute it in the loop below)
|
||||
if toc[i].depth > max_depth then
|
||||
max_depth = toc[i].depth
|
||||
local depth = item.depth
|
||||
if depth > max_depth then
|
||||
max_depth = depth
|
||||
end
|
||||
-- Also use this loop to compute seq_in_level for each
|
||||
-- item, needed by BookMap with alternative theme
|
||||
local seq = (cur_seq_by_level[depth] or 0) + 1
|
||||
item.seq_in_level = seq
|
||||
cur_seq_by_level[depth] = seq
|
||||
end
|
||||
if not has_bogus then -- no TOC items, or all are valid
|
||||
logger.dbg("validateAndFixToc(): TOC is fine")
|
||||
@@ -203,6 +211,7 @@ function ReaderToc:validateAndFixToc()
|
||||
-- Bad ordering previously noticed: try to fix the wrong items' page
|
||||
-- by setting it to the previous or next good item page.
|
||||
max_depth = 0 -- recompute this
|
||||
cur_seq_by_level = {}
|
||||
local nb_bogus = 0
|
||||
local nb_fixed_pages = 0
|
||||
-- We fix only one bogus item per loop, taking the option that
|
||||
@@ -215,10 +224,17 @@ function ReaderToc:validateAndFixToc()
|
||||
-- (These cases are met in the following code with cur_page=57 and page=6)
|
||||
cur_page = 0
|
||||
for i = first, last do
|
||||
if toc[i].depth > max_depth then
|
||||
max_depth = toc[i].depth
|
||||
local item = toc[i]
|
||||
-- Recompute max_depth and item's seq_in_level
|
||||
local depth = item.depth
|
||||
if depth > max_depth then
|
||||
max_depth = depth
|
||||
end
|
||||
local page = toc[i].fixed_page or toc[i].page
|
||||
local seq = (cur_seq_by_level[depth] or 0) + 1
|
||||
item.seq_in_level = seq
|
||||
cur_seq_by_level[depth] = seq
|
||||
-- Look for bogus page
|
||||
local page = item.fixed_page or item.page
|
||||
if page >= cur_page then
|
||||
cur_page = page
|
||||
else
|
||||
@@ -272,7 +288,7 @@ function ReaderToc:validateAndFixToc()
|
||||
logger.dbg(" fix next", j, toc[j].page, "=>", fixed_page)
|
||||
end
|
||||
end
|
||||
cur_page = toc[i].fixed_page or toc[i].page
|
||||
cur_page = item.fixed_page or item.page
|
||||
end
|
||||
end
|
||||
if nb_bogus > 0 then
|
||||
|
||||
@@ -232,12 +232,21 @@ function BookMapRow:init()
|
||||
text_widget = nil
|
||||
end
|
||||
end
|
||||
-- Different style depending on alt_theme
|
||||
local bgcolor = Blitbuffer.COLOR_WHITE
|
||||
if self.alt_theme then
|
||||
if item.seq_in_level % 2 == 0 then -- alternate background color
|
||||
bgcolor = Blitbuffer.COLOR_GRAY_E
|
||||
else
|
||||
bgcolor = Blitbuffer.COLOR_GRAY_B
|
||||
end
|
||||
end
|
||||
local span_w = FrameContainer:new{
|
||||
overlap_offset = {offset_x, offset_y},
|
||||
margin = 0,
|
||||
padding = 0,
|
||||
bordersize = self.toc_span_border,
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
background = bgcolor,
|
||||
CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = width - 2 * self.toc_span_border,
|
||||
@@ -312,7 +321,9 @@ function BookMapRow:init()
|
||||
table.insert(self.background_fillers, {
|
||||
x = x, y = 0,
|
||||
w = w, h = self.pages_frame_height,
|
||||
color = Blitbuffer.COLOR_LIGHT_GRAY,
|
||||
-- Different style depending on alt_theme
|
||||
color = self.alt_theme and Blitbuffer.COLOR_GRAY or Blitbuffer.COLOR_LIGHT_GRAY,
|
||||
stripe_width = self.alt_theme and math.ceil(self.span_height / 10) or nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
@@ -526,7 +537,11 @@ end
|
||||
function BookMapRow:paintTo(bb, x, y)
|
||||
-- Paint background fillers (which are not subwidgets) first
|
||||
for _, filler in ipairs(self.background_fillers) do
|
||||
bb:paintRect(x + self.pages_frame_offset_x + filler.x, y + filler.y, filler.w, filler.h, filler.color)
|
||||
if filler.stripe_width then
|
||||
bb:hatchRect(x + self.pages_frame_offset_x + filler.x, y + filler.y, filler.w, filler.h, filler.stripe_width, filler.color)
|
||||
else
|
||||
bb:paintRect(x + self.pages_frame_offset_x + filler.x, y + filler.y, filler.w, filler.h, filler.color)
|
||||
end
|
||||
end
|
||||
-- Paint regular sub widgets the classic way
|
||||
InputContainer.paintTo(self, bb, x, y)
|
||||
@@ -828,6 +843,8 @@ function BookMapWidget:update()
|
||||
self.vgroup:clear()
|
||||
self.cropping_widget:reset()
|
||||
|
||||
self.alt_theme = G_reader_settings:isTrue("book_map_alt_theme")
|
||||
|
||||
-- Flat book map has each TOC item on a new line, and pages graph underneath.
|
||||
-- Non-flat book map shows a grid with TOC items following each others.
|
||||
self.flat_map = self.ui.doc_settings:readSetting("book_map_flat", false)
|
||||
@@ -987,6 +1004,7 @@ function BookMapWidget:update()
|
||||
title = item.title,
|
||||
p_start = item.page,
|
||||
p_end = nil,
|
||||
seq_in_level = item.seq_in_level,
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -1090,6 +1108,7 @@ function BookMapWidget:update()
|
||||
nb_toc_spans = self.nb_toc_spans,
|
||||
span_height = self.span_height,
|
||||
font_face = self.toc_span_face,
|
||||
alt_theme = self.alt_theme,
|
||||
start_page_text = start_page_text,
|
||||
start_page = p_start,
|
||||
end_page = p_end,
|
||||
@@ -1197,6 +1216,31 @@ function BookMapWidget:showMenu()
|
||||
b:refresh()
|
||||
end,
|
||||
}},
|
||||
{{
|
||||
text_func = function(no_size_trick)
|
||||
local text = _("Alternative theme")
|
||||
if G_reader_settings:isTrue("book_map_alt_theme") then
|
||||
text = text .. " \u{2713}" -- checkmark
|
||||
else
|
||||
if not no_size_trick then
|
||||
-- Initial call, make it wide enough so the checkmark text will fit
|
||||
text = text .. " \u{2003}" -- wide em space
|
||||
end
|
||||
-- Otherwise, keep it small without the checkmark, which will fit
|
||||
end
|
||||
return text
|
||||
end,
|
||||
id = "alt_theme",
|
||||
align = "left",
|
||||
callback = function()
|
||||
G_reader_settings:flipTrue("book_map_alt_theme")
|
||||
local b = button_dialog:getButtonById("alt_theme")
|
||||
b:setText(b.text_func(true), b.width)
|
||||
b:refresh()
|
||||
self.editable_stuff_edited = true -- have this change reflected on any lower bookmap & pagebrowser
|
||||
self:update()
|
||||
end,
|
||||
}},
|
||||
not self.overview_mode and {{
|
||||
text = _("Switch current/initial views"),
|
||||
align = "left",
|
||||
|
||||
@@ -497,7 +497,6 @@ function PageBrowserWidget:update()
|
||||
|
||||
-- We need to rebuilt the full set of toc spans that will be shown
|
||||
-- Similar (but simplified) to what is done in BookMapWidget.
|
||||
self.toc_depth = self.nb_toc_spans
|
||||
local toc = self.ui.toc.toc
|
||||
local cur_toc_items = {}
|
||||
local row_toc_items = {}
|
||||
@@ -508,9 +507,9 @@ function PageBrowserWidget:update()
|
||||
if item.page > p_end then
|
||||
break
|
||||
end
|
||||
if item.depth <= self.toc_depth then -- ignore lower levels we won't show
|
||||
if item.depth <= self.nb_toc_spans then -- ignore lower levels we won't show
|
||||
-- An item at level N closes all previous items at level >= N
|
||||
for lvl = item.depth, self.toc_depth do
|
||||
for lvl = item.depth, self.nb_toc_spans do
|
||||
local done_toc_item = cur_toc_items[lvl]
|
||||
cur_toc_items[lvl] = nil
|
||||
if done_toc_item then
|
||||
@@ -533,6 +532,7 @@ function PageBrowserWidget:update()
|
||||
title = item.title,
|
||||
p_start = item.page,
|
||||
p_end = nil,
|
||||
seq_in_level = item.seq_in_level,
|
||||
}
|
||||
end
|
||||
toc_idx = toc_idx + 1
|
||||
@@ -572,6 +572,7 @@ function PageBrowserWidget:update()
|
||||
nb_toc_spans = self.nb_toc_spans,
|
||||
span_height = self.span_height,
|
||||
font_face = self.toc_span_face,
|
||||
alt_theme = G_reader_settings:isTrue("book_map_alt_theme"),
|
||||
start_page_text = "",
|
||||
start_page = p_start,
|
||||
end_page = p_end,
|
||||
@@ -748,6 +749,19 @@ function PageBrowserWidget:showTile(grid_idx, page, tile, do_refresh)
|
||||
-- thumb_frame will overflow its CenterContainer because of the added borders,
|
||||
-- but CenterContainer handles that well. We will refresh the outer dimensions.
|
||||
|
||||
if self.has_hidden_flows and self.ui.document:getPageFlow(page) ~= 0 then
|
||||
-- We want to distinguish pages part of hidden flow.
|
||||
-- Using a uniform gray background may not be enough on scanned PDF
|
||||
-- gray pages non-dewatermarked, so we use diagonal gray stripes.
|
||||
-- We use a gray background similar to how it appears on hidden flows
|
||||
-- in the BookMapRow, where they are COLOR_LIGHT_GRAY (0xCC).
|
||||
-- To achieve the same color, we can use COLOR_BLACK with alpha = 0.2.
|
||||
thumb_frame.stripe_width = math.ceil(math.min(self.grid_item_width, self.grid_item_height) / 2)
|
||||
thumb_frame.stripe_color = Blitbuffer.COLOR_BLACK
|
||||
thumb_frame.stripe_over = true
|
||||
thumb_frame.stripe_over_alpha = 0.2
|
||||
end
|
||||
|
||||
local page_num_widget
|
||||
if item_frame.show_pagenum and self.pagenum_page_texts[page] then
|
||||
local page_text = table.concat(util.splitToChars(self.pagenum_page_texts[page]), "\n")
|
||||
|
||||
Reference in New Issue
Block a user