From d352579d0647aa5832508ae2277a746e3ed14684 Mon Sep 17 00:00:00 2001 From: poire-z Date: Wed, 3 Aug 2022 08:45:45 +0200 Subject: [PATCH] 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). --- frontend/ui/widget/bookmapwidget.lua | 27 ++++++++++++++++++--------- plugins/statistics.koplugin/main.lua | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/frontend/ui/widget/bookmapwidget.lua b/frontend/ui/widget/bookmapwidget.lua index a10733cb8..d65e4472a 100644 --- a/frontend/ui/widget/bookmapwidget.lua +++ b/frontend/ui/widget/bookmapwidget.lua @@ -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{ diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 39531866e..bc10c16b7 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -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)