From 4732bc9aed0366cabee0a2db5551fe0f3af03e90 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 8 Jan 2023 23:37:35 +0100 Subject: [PATCH] ReaderView: Recompute page layout when toggling ReaderFooter in non-reflowable documents. The code only handled setups with "reclaim bar height" enabled (because that's my usual workflow, har har), but would have broken in various more or less obvious ways without it, depending on the exact layout/zoom settings. The previous attempts at handling the no-reclaim case were focused on scroll mode, which is a bit of a nightmare. This approach should deal as well/badly as the previous one in scroll mode, but actually handle page mode properly ;). Re #9979 --- frontend/apps/reader/modules/readerfooter.lua | 2 +- frontend/apps/reader/modules/readerview.lua | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 60a7c49c5..30ca36a3c 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -2199,8 +2199,8 @@ function ReaderFooter:_updateFooterText(force_repaint, force_recompute) if force_repaint then -- If there was a visibility change, notify ReaderView if self.visibility_change then - self.ui:handleEvent(Event:new("ReaderFooterVisibilityChange")) self.visibility_change = nil + self.ui:handleEvent(Event:new("ReaderFooterVisibilityChange")) end -- NOTE: Getting the dimensions of the widget is impossible without having drawn it first, diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index f616fe7a6..b8f8f3a35 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -968,19 +968,15 @@ end function ReaderView:onReaderFooterVisibilityChange() -- Don't bother ReaderRolling with this nonsense, the footer's height is NOT handled via visible_area there ;) if self.ui.paging and self.state.page then - -- NOTE: Simply relying on recalculate would be a wee bit too much: it'd reset the in-page offsets, - -- which would be wrong, and is also not necessary, since the footer is at the bottom of the screen ;). - -- So, simply mangle visible_area's height ourselves... + -- We don't need to do anything if reclaim is enabled ;). if not self.footer.settings.reclaim_height then - -- NOTE: Yes, this means that toggling reclaim_height requires a page switch (for a proper recalculate). - -- Thankfully, most of the time, the quirks are barely noticeable ;). - if self.footer_visible then - self.visible_area.h = self.visible_area.h - self.footer:getHeight() - else - self.visible_area.h = self.visible_area.h + self.footer:getHeight() - end + -- NOTE: Mimic what onSetFullScreen does, since, without reclaim, toggling the footer affects the available area, + -- so we need to recompute the full layout. + self.ui:handleEvent(Event:new("SetDimensions", Screen:getSize())) + -- NOTE: Scroll mode's behavior after this might be suboptimal (until next page), + -- but I'm not familiar enough with it to make it behave... + -- (e.g., RedrawCurrentPage & co will snap to the top of the "current" page). end - self.ui:handleEvent(Event:new("ViewRecalculate", self.visible_area, self.page_area)) end end