2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00

cre 2-pages view: fix markers when following links and back

Show markers in the middle margin when target is in the right page.
This commit is contained in:
poire-z 2019-03-13 13:09:44 +01:00
parent 22bc9dacb5
commit 220b2dcfc2
2 changed files with 33 additions and 6 deletions

View File

@ -529,16 +529,32 @@ function ReaderRolling:onGotoXPointer(xp, marker_xp)
if marker_xp and marker_setting then
-- Show a mark on left side of screen to give a visual feedback of
-- where xpointer target is (and remove if after 1s)
local screen_y = self.ui.document:getScreenPositionFromXPointer(marker_xp)
local screen_y, screen_x = self.ui.document:getScreenPositionFromXPointer(marker_xp)
local doc_margins = self.ui.document:getPageMargins()
local marker_h = Screen:scaleBySize(self.ui.font.font_size * 1.1 * self.ui.font.line_space_percent/100.0)
-- Make it 4/5 of left margin wide (and bigger when huge margin)
local marker_w = math.floor(math.max(doc_margins["left"] - Screen:scaleBySize(5), doc_margins["left"] * 4/5))
if self.ui.document:getVisiblePageCount() > 1 and screen_x > Screen:getWidth() / 2 then
-- On right page in 2-pages mode
-- We could show the marker on the right of the page with:
-- screen_x = Screen:getWidth() - marker_w
-- But it's best to show it on the left of text, so in
-- the middle margin, so it still shows just left of a
-- footnote number.
-- This is a bit tricky with how the middle margin is sized
-- by crengine (see LVDocView::updateLayout() in lvdocview.cpp)
screen_x = Screen:getWidth() / 2
local page2_x = self.ui.document._document:getPageOffsetX(self.ui.document:getCurrentPage()+1)
marker_w = page2_x + marker_w - screen_x
else
screen_x = 0
end
self.mark_func = function()
self.mark_func = nil
Screen.bb:paintRect(0, screen_y, marker_w, marker_h, Blitbuffer.COLOR_BLACK)
Screen["refreshFast"](Screen, 0, screen_y, marker_w, marker_h)
Screen.bb:paintRect(screen_x, screen_y, marker_w, marker_h, Blitbuffer.COLOR_BLACK)
Screen["refreshFast"](Screen, screen_x, screen_y, marker_w, marker_h)
if type(marker_setting) == "number" then -- hide it
self.unmark_func = function()
self.unmark_func = nil
@ -547,8 +563,8 @@ function ReaderRolling:onGotoXPointer(xp, marker_xp)
-- re-render the page, which may take a few seconds on big
-- documents): we drew our black marker in the margin, we
-- can just draw a white one to make it disappear
Screen.bb:paintRect(0, screen_y, marker_w, marker_h, Blitbuffer.COLOR_WHITE)
Screen["refreshUI"](Screen, 0, screen_y, marker_w, marker_h)
Screen.bb:paintRect(screen_x, screen_y, marker_w, marker_h, Blitbuffer.COLOR_WHITE)
Screen["refreshUI"](Screen, screen_x, screen_y, marker_w, marker_h)
end
UIManager:scheduleIn(marker_setting, self.unmark_func)
end

View File

@ -418,10 +418,21 @@ function CreDocument:getScreenPositionFromXPointer(xp)
local doc_y, doc_x = self:getPosFromXPointer(xp)
local top_y = self:getCurrentPos()
local screen_y = doc_y - top_y
local screen_x = doc_x + doc_margins["left"]
if self._view_mode == self.PAGE_VIEW_MODE then
if self:getVisiblePageCount() > 1 then
-- Correct coordinates if on the 2nd page in 2-pages mode
local next_page = self:getCurrentPage() + 1
if next_page <= self:getPageCount() then
local next_top_y = self._document:getPageStartY(next_page)
if doc_y >= next_top_y then
screen_y = doc_y - next_top_y
screen_x = screen_x + self._document:getPageOffsetX(next_page)
end
end
end
screen_y = screen_y + doc_margins["top"] + self:getHeaderHeight()
end
local screen_x = doc_x + doc_margins["left"]
-- Just as getPosFromXPointer() does, we return y first and x second,
-- as callers most often just need the y
return screen_y, screen_x