From 658f513512ee32e6b989bb4da150909b89a9c42a Mon Sep 17 00:00:00 2001 From: poire-z Date: Sun, 10 Mar 2019 21:50:11 +0100 Subject: [PATCH] [fix] cre: fix position and page number after window resize (#4754) --- .../apps/reader/modules/readerrolling.lua | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/frontend/apps/reader/modules/readerrolling.lua b/frontend/apps/reader/modules/readerrolling.lua index 94f20b58d..0dc0e6c3d 100644 --- a/frontend/apps/reader/modules/readerrolling.lua +++ b/frontend/apps/reader/modules/readerrolling.lua @@ -665,21 +665,34 @@ function ReaderRolling:onRedrawCurrentView() end function ReaderRolling:onSetDimensions(dimen) - self.ui.document:setViewDimen(Screen:getSize()) + if self.ui.postReaderCallback ~= nil then + -- ReaderUI:init() not yet done: just set document dimensions + self.ui.document:setViewDimen(Screen:getSize()) + -- (what's done in the following else is done elsewhere by + -- the initialization code) + else + -- Initialization done: we are called on orientation change + -- or on window resize (SDL, Android possibly). + -- We need to temporarily re-enable internal history as crengine + -- uses it to reposition after resize + self.ui.document:enableInternalHistory(true) + -- Set document dimensions + self.ui.document:setViewDimen(Screen:getSize()) + -- Re-setup previous position + self:onChangeViewMode() + self:onUpdatePos() + -- Re-disable internal history, with required redraw + self.ui.document:enableInternalHistory(false) + self:onRedrawCurrentView() + end end function ReaderRolling:onChangeScreenMode(mode, rotation) - -- We need to temporarily re-enable internal history as crengine - -- uses it to reposition after resize - self.ui.document:enableInternalHistory(true) - -- Flag it as interactive so we can properly swap to Inverted orientations (we usurp the second argument, which usually means rotation) + -- Flag it as interactive so we can properly swap to Inverted orientations + -- (we usurp the second argument, which usually means rotation) self.ui:handleEvent(Event:new("SetScreenMode", mode, rotation or true)) - self.ui.document:setViewDimen(Screen:getSize()) - self:onChangeViewMode() - self:onUpdatePos() - -- Re-disable internal history, with required redraw - self.ui.document:enableInternalHistory(false) - self:onRedrawCurrentView() + -- (This had the above ReaderRolling:onSetDimensions() called to resize + -- document dimensions and keep up with current position) end function ReaderRolling:onColorRenderingUpdate()