BookMap: allow tap on ToC titles and outside page slots (#9400)

This helps jumping to page when ToC chapters are short
and the bookmap page rows narrow.
Also fix crash when invoking BookMap and PageBrowser
on a PicDocument (considered DocLess by Statistics).
reviewable/pr9402/r1
poire-z 2 years ago committed by GitHub
parent ad7cfa2c4b
commit d352579d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -67,10 +67,15 @@ function BookMapRow:getPageX(page, right_edge)
return x
end
function BookMapRow:getPageAtX(x)
function BookMapRow:getPageAtX(x, at_bounds_if_outside)
x = x - self.pages_frame_offset_x
if x < 0 or x >= self.pages_frame_inner_width then
return
if x < 0 then
if not at_bounds_if_outside then return end
x = 0
end
if x >= self.pages_frame_inner_width then
if not at_bounds_if_outside then return end
x = self.pages_frame_inner_width - 1
end
-- Reverse of the computation in :getPageX():
local slot_idx = math.floor(x / (self.page_slot_width + self.page_slot_extra / self.nb_page_slots))
@ -834,7 +839,9 @@ function BookMapWidget:update()
text = self.ui.toc:cleanUpTocTitle(item.title, true),
width = txt_max_width,
face = self.flat_toc_depth_faces[item.depth],
}
},
-- Store this TOC item page, so we can tap on it to launch PageBrowser on its page
toc_item_page = item.page,
})
-- Add a bit more spacing for the BookMapRow(s) underneath this Toc item title
-- (so the page number painted in this spacing feels included in the indentation)
@ -1348,14 +1355,16 @@ function BookMapWidget:onTap(arg, ges)
end
local x, y = ges.pos.x, ges.pos.y
local row, row_idx, row_y, row_h = self:getVGroupRowAtY(y-self.title_bar_h) -- luacheck: no unused
if not row or not row.start_page then
-- not a BookMapRow, probably a TOC title
if not row then
return true
end
if BD.mirroredUILayout() then
x = x - self.scrollbar_width
local page = row.toc_item_page -- it might be a TOC title
if not page and row.start_page then -- or a BookMapRow
if BD.mirroredUILayout() then
x = x - self.scrollbar_width
end
page = row:getPageAtX(x, true)
end
local page = row:getPageAtX(x)
if page then
local PageBrowserWidget = require("ui/widget/pagebrowserwidget")
UIManager:show(PageBrowserWidget:new{

@ -236,7 +236,7 @@ function ReaderStatistics:initData()
end
function ReaderStatistics:isEnabled()
return self.settings.is_enabled
return not self:isDocless() and self.settings.is_enabled
end
-- Reset the (volatile) stats on page count changes (e.g., after a font size update)

Loading…
Cancel
Save