diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index e89b0b735..879092307 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -380,7 +380,6 @@ local ReaderFooter = WidgetContainer:extend{ text_font_face = "ffont", height = Screen:scaleBySize(DMINIBAR_CONTAINER_HEIGHT), horizontal_margin = Size.span.horizontal_default, - text_left_margin = Size.span.horizontal_default, bottom_padding = Size.padding.tiny, settings = {}, -- added to expose them to unit tests @@ -740,7 +739,7 @@ function ReaderFooter:resetLayout(force_reset) self.progress_bar.width = math.floor(new_screen_width - 2 * self.settings.progress_margin_width) else self.progress_bar.width = math.floor( - new_screen_width - self.text_width - self.settings.progress_margin_width*2) + new_screen_width - 2 * self.settings.progress_margin_width - self.text_width) end if self.separator_line then self.separator_line.dimen.w = new_screen_width - 2 * self.horizontal_margin @@ -1480,10 +1479,14 @@ function ReaderFooter:addToMainMenu(menu_items) return not self.settings.progress_bar_position end, callback = function() + -- "Same as book" is disabled in this mode, and we enforce the defaults. if self.settings.progress_margin then self.settings.progress_margin = false - self.settings.progress_margin_width = Size.span.horizontal_default + self.settings.progress_margin_width = self.horizontal_margin end + -- Text alignment is also disabled + self.settings.align = "center" + self.settings.progress_bar_position = nil self:refreshFooter(true, true) end @@ -1907,12 +1910,13 @@ function ReaderFooter:_updateFooterText(force_repaint, force_recompute) local text = self:genFooterText() if not text then text = "" end self.footer_text:setText(text) - self.footer_text:setMaxWidth(math.floor(self._saved_screen_width - 2 * self.settings.progress_margin_width)) if self.settings.disable_progress_bar then if self.has_no_mode or text == "" then self.text_width = 0 self.footer_text.height = 0 else + -- No progress bar, we're only constrained to fit inside self.footer_container + self.footer_text:setMaxWidth(math.floor(self._saved_screen_width - 2 * self.horizontal_margin)) self.text_width = self.footer_text:getSize().w self.footer_text.height = self.footer_text:getSize().h end @@ -1923,6 +1927,13 @@ function ReaderFooter:_updateFooterText(force_repaint, force_recompute) self.text_width = 0 self.footer_text.height = 0 else + -- With a progress bar above or below us, we want to align ourselves to the bar's margins... iff text is centered. + if self.settings.align == "center" then + self.footer_text:setMaxWidth(math.floor(self._saved_screen_width - 2 * self.settings.progress_margin_width)) + else + -- Otherwise, we have to constrain ourselves to the container, or weird shit happens. + self.footer_text:setMaxWidth(math.floor(self._saved_screen_width - 2 * self.horizontal_margin)) + end self.text_width = self.footer_text:getSize().w self.footer_text.height = self.footer_text:getSize().h end @@ -1932,13 +1943,15 @@ function ReaderFooter:_updateFooterText(force_repaint, force_recompute) self.text_width = 0 self.footer_text.height = 0 else + -- Alongside a progress bar, it's the bar's width plus whatever's left. local text_max_available_ratio = (100 - self.settings.progress_bar_min_width_pct) / 100 - self.footer_text:setMaxWidth(math.floor(text_max_available_ratio * self._saved_screen_width - 2 * self.settings.progress_margin_width)) - self.text_width = self.footer_text:getSize().w + self.text_left_margin + self.footer_text:setMaxWidth(math.floor(text_max_available_ratio * self._saved_screen_width - 2 * self.settings.progress_margin_width - self.horizontal_margin)) + -- Add some spacing between the text and the bar + self.text_width = self.footer_text:getSize().w + self.horizontal_margin self.footer_text.height = self.footer_text:getSize().h end self.progress_bar.width = math.floor( - self._saved_screen_width - self.text_width - self.settings.progress_margin_width*2) + self._saved_screen_width - 2 * self.settings.progress_margin_width - self.text_width) end if self.separator_line then diff --git a/spec/unit/readerfooter_spec.lua b/spec/unit/readerfooter_spec.lua index 6397592b9..4ff82cb92 100644 --- a/spec/unit/readerfooter_spec.lua +++ b/spec/unit/readerfooter_spec.lua @@ -658,7 +658,7 @@ describe("Readerfooter module", function() tapFooterMenu(fake_menu, "Progress percentage".." (⤠)") assert.are.same('⤠ 0%', footer.footer_text.text) assert.is.same(false, footer.has_no_mode) - assert.is.same(footer.footer_text:getSize().w + footer.text_left_margin, + assert.is.same(footer.footer_text:getSize().w + footer.horizontal_margin, footer.text_width) tapFooterMenu(fake_menu, "Progress percentage".." (⤠)") assert.is.same(true, footer.has_no_mode)