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
if self.settings.toc_markers then
self.progress_bar.tick_width = Screen:scaleBySize(self.settings.toc_markers_width)
if self.progress_bar.ticks ~= nil then return end
local ticks_candidates = {}
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)
if self.progress_bar.ticks ~= nil then -- already computed
return
end
if #ticks_candidates > 0 then
self.progress_bar.ticks = ticks_candidates[1]
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 = {}
self.progress_bar.ticks = {}
if self.ui.toc then
self.progress_bar.ticks = self.ui.toc:getTocTicksForFooter()
end
self.progress_bar.last = self.pages or self.view.document:getPageCount()
else
self.progress_bar.ticks = nil
end

@ -814,6 +814,7 @@ function ReaderRolling:updatePos()
self.ui:handleEvent(Event:new("UpdateToc"))
self.view.footer:updateFooter()
end
self:updateTopStatusBarMarkers()
UIManager:setDirty(self.view.dialog, "partial")
-- Allow for the new rendering to be shown before possibly showing
-- 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"))
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()
if self.view.view_mode == "page" and self.cre_top_bar_enabled then
logger.dbg("update battery state")

@ -285,6 +285,21 @@ function ReaderToc:getTocTicks(level)
return ticks
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)
local ticks = self:getTocTicks(level)
local next_chapter = nil

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

Loading…
Cancel
Save