CRE: use same marks in top and bottom progress bars

Feed to crengine the same ticks (build from the TOC
entries) that we use in the bottom status bar.
(crengine otherwise builds a tick for each DocFragment,
which most often is really different than what's seen
in the bottom bar.)
reviewable/pr6240/r1
poire-z 4 years ago committed by Frans de Jonge
parent 3e71e4985e
commit 5536ce996a

@ -1581,26 +1581,14 @@ function ReaderFooter:setTocMarkers(reset)
end end
if self.settings.toc_markers then if self.settings.toc_markers then
self.progress_bar.tick_width = Screen:scaleBySize(self.settings.toc_markers_width) self.progress_bar.tick_width = Screen:scaleBySize(self.settings.toc_markers_width)
if self.progress_bar.ticks ~= nil then return end if self.progress_bar.ticks ~= nil then -- already computed
local ticks_candidates = {} return
if self.ui.toc then
local max_level = self.ui.toc:getMaxDepth()
for i = 0, -max_level, -1 do
local ticks = self.ui.toc:getTocTicks(i)
table.insert(ticks_candidates, ticks)
end
-- find the finest toc ticks by sorting out the largest one
table.sort(ticks_candidates, function(a, b) return #a > #b end)
end end
self.progress_bar.ticks = {}
if #ticks_candidates > 0 then if self.ui.toc then
self.progress_bar.ticks = ticks_candidates[1] self.progress_bar.ticks = self.ui.toc:getTocTicksForFooter()
self.progress_bar.last = self.pages or self.view.document:getPageCount()
else
-- we still set ticks here so self.progress_bar.ticks will not be
-- initialized again if ticks_candidates is empty
self.progress_bar.ticks = {}
end end
self.progress_bar.last = self.pages or self.view.document:getPageCount()
else else
self.progress_bar.ticks = nil self.progress_bar.ticks = nil
end end

@ -814,6 +814,7 @@ function ReaderRolling:updatePos()
self.ui:handleEvent(Event:new("UpdateToc")) self.ui:handleEvent(Event:new("UpdateToc"))
self.view.footer:updateFooter() self.view.footer:updateFooter()
end end
self:updateTopStatusBarMarkers()
UIManager:setDirty(self.view.dialog, "partial") UIManager:setDirty(self.view.dialog, "partial")
-- Allow for the new rendering to be shown before possibly showing -- Allow for the new rendering to be shown before possibly showing
-- the "Styles have changes..." ConfirmBox so the user can decide -- the "Styles have changes..." ConfirmBox so the user can decide
@ -1005,6 +1006,15 @@ function ReaderRolling:onSetStatusLine(status_line, on_read_settings)
self.ui:handleEvent(Event:new("UpdatePos")) self.ui:handleEvent(Event:new("UpdatePos"))
end end
function ReaderRolling:updateTopStatusBarMarkers()
if not self.cre_top_bar_enabled then
return
end
local pages = self.ui.document:getPageCount()
local ticks = self.ui.toc:getTocTicksForFooter()
self.ui.document:setHeaderProgressMarks(pages, ticks)
end
function ReaderRolling:updateBatteryState() function ReaderRolling:updateBatteryState()
if self.view.view_mode == "page" and self.cre_top_bar_enabled then if self.view.view_mode == "page" and self.cre_top_bar_enabled then
logger.dbg("update battery state") logger.dbg("update battery state")

@ -285,6 +285,21 @@ function ReaderToc:getTocTicks(level)
return ticks return ticks
end end
function ReaderToc:getTocTicksForFooter()
local ticks_candidates = {}
local max_level = self:getMaxDepth()
for i = 0, -max_level, -1 do
local ticks = self:getTocTicks(i)
table.insert(ticks_candidates, ticks)
end
if #ticks_candidates > 0 then
-- Find the finest toc ticks by sorting out the largest one
table.sort(ticks_candidates, function(a, b) return #a > #b end)
return ticks_candidates[1]
end
return {}
end
function ReaderToc:getNextChapter(cur_pageno, level) function ReaderToc:getNextChapter(cur_pageno, level)
local ticks = self:getTocTicks(level) local ticks = self:getTocTicks(level)
local next_chapter = nil local next_chapter = nil

@ -767,6 +767,10 @@ function CreDocument:setViewDimen(dimen)
self._document:setViewDimen(dimen.w, dimen.h) self._document:setViewDimen(dimen.w, dimen.h)
end end
function CreDocument:setHeaderProgressMarks(pages, ticks)
self._document:setHeaderProgressMarks(pages, ticks)
end
function CreDocument:setHeaderFont(new_font) function CreDocument:setHeaderFont(new_font)
if new_font then if new_font then
logger.dbg("CreDocument: set header font", new_font) logger.dbg("CreDocument: set header font", new_font)

Loading…
Cancel
Save