Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure minimum height for the in-fill in progress bar #6878

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/apps/reader/modules/readerfooter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ function ReaderFooter:resetLayout(force_reset)
else
bar_height = self.settings.progress_style_thick_height or PROGRESS_BAR_STYLE_THICK_DEFAULT_HEIGHT
end
self.progress_bar.height = Screen:scaleBySize(bar_height)
self.progress_bar:setHeight(bar_height)
Copy link
Member

@NiLuJe NiLuJe Nov 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another instance of this @ L1836

(Which I'm not quite sure is actually necessary at all, because it has nothing whatsoever to do with what that function's supposed to do... It feels like a leftover from a c/p from this resetLayout, actually)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I had searched for other instances, obviously I missed at least one.


self.horizontal_group:resetLayout()
self.footer_positioner.dimen.w = new_screen_width
Expand Down Expand Up @@ -1820,7 +1820,7 @@ function ReaderFooter:_updateFooterText(force_repaint, force_recompute)
else
bar_height = self.settings.progress_style_thick_height or PROGRESS_BAR_STYLE_THICK_DEFAULT_HEIGHT
end
self.progress_bar.height = Screen:scaleBySize(bar_height)
self.progress_bar:setHeight(bar_height)

if self.separator_line then
self.separator_line.dimen.w = self._saved_screen_width - 2 * self.horizontal_margin
Expand Down
30 changes: 25 additions & 5 deletions frontend/ui/widget/progresswidget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ local ProgressWidget = Widget:new{
fill_from_right = false,
allow_mirroring = true,
_mirroredUI = BD.mirroredUILayout(),
_orig_margin_v = nil,
_orig_bordersize = nil,
}

function ProgressWidget:getSize()
Expand Down Expand Up @@ -124,26 +126,44 @@ function ProgressWidget:getPercentageFromPosition(pos)
return x / width
end

function ProgressWidget:setHeight(height)
self.height = Screen:scaleBySize(height)
-- Adjust vertical margin and border size to ensure there's
-- at least 1 pixel left for the actual bar
self._orig_margin_v = self._orig_margin_v or self.margin_v
self._orig_bordersize = self._orig_bordersize or self.bordersize
local margin_v_min = self._orig_margin_v > 0 and 1 or 0
local bordersize_min = self._orig_bordersize > 0 and 1 or 0
self.margin_v = math.min(self._orig_margin_v, math.floor((self.height - 2*self._orig_bordersize - 1) / 2))
self.margin_v = math.max(self.margin_v, margin_v_min)
self.bordersize = math.min(self._orig_bordersize, math.floor((self.height - 2*self.margin_v - 1) / 2))
self.bordersize = math.max(self.bordersize, bordersize_min)
end

function ProgressWidget:updateStyle(thick, height)
if thick then
if height then
self.height = Screen:scaleBySize(height)
end
self.margin_h = Screen:scaleBySize(3)
self.margin_v = Screen:scaleBySize(1)
self.bordersize = Screen:scaleBySize(1)
self.radius = Screen:scaleBySize(2)
self.bgcolor = Blitbuffer.COLOR_WHITE
else
self._orig_margin_v = nil
self._orig_bordersize = nil
if height then
self.height = Screen:scaleBySize(height)
self:setHeight(height)
end
else
self.margin_h = 0
self.margin_v = 0
self.bordersize = 0
self.radius = 0
self.bgcolor = Blitbuffer.COLOR_GRAY
self.ticks = nil
self._orig_margin_v = nil
self._orig_bordersize = nil
if height then
self:setHeight(height)
end
end
end

Expand Down