android: replace default footer margins by values that work with rounded corner devices (#6260)

That's it: replace "static 10px" margins by a value that takes device DPI into account and works with rounded corner devices.

Fixes #6157
reviewable/pr6262/r1
Martín Fernández 4 years ago committed by GitHub
parent e3f978be2c
commit 2f831bebc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -96,6 +96,9 @@ local PROGRESS_BAR_STYLE_THIN_DEFAULT_HEIGHT = 3
local DMINIBAR_TOC_MARKER_WIDTH = 2 local DMINIBAR_TOC_MARKER_WIDTH = 2
local DMINIBAR_FONT_SIZE = 14 local DMINIBAR_FONT_SIZE = 14
-- android: guidelines for rounded corner margins
local material_pixels = 16 * math.floor(Screen:getDPI() / 160)
-- functions that generates footer text for each mode -- functions that generates footer text for each mode
local footerTextGeneratorMap = { local footerTextGeneratorMap = {
empty = function() return "" end, empty = function() return "" end,
@ -376,7 +379,8 @@ function ReaderFooter:init()
-- default margin (like self.horizontal_margin) -- default margin (like self.horizontal_margin)
if not self.settings.progress_margin_width then if not self.settings.progress_margin_width then
self.settings.progress_margin_width = Screen:scaleBySize(10) local defaults = Device:isAndroid() and material_pixels or 10
self.settings.progress_margin_width = Screen:scaleBySize(defaults)
end end
if not self.settings.toc_markers_width then if not self.settings.toc_markers_width then
self.settings.toc_markers_width = DMINIBAR_TOC_MARKER_WIDTH self.settings.toc_markers_width = DMINIBAR_TOC_MARKER_WIDTH
@ -1442,8 +1446,11 @@ function ReaderFooter:addToMainMenu(menu_items)
{ {
text_func = function() text_func = function()
local text = _("static margins (10)") local text = _("static margins (10)")
if self.settings.progress_margin_width == Screen:scaleBySize(0) then local cur_width = self.settings.progress_margin_width
if cur_width == Screen:scaleBySize(0) then
text = _("no margins (0)") text = _("no margins (0)")
elseif cur_width == Screen:scaleBySize(material_pixels) then
text = T(_("static margins (%1)"), material_pixels)
end end
if self.settings.progress_margin and not self.ui.document.info.has_pages then if self.settings.progress_margin and not self.ui.document.info.has_pages then
text = T(_("same as book margins (%1)"), self.book_margins_footer_width) text = T(_("same as book margins (%1)"), self.book_margins_footer_width)
@ -1453,53 +1460,65 @@ function ReaderFooter:addToMainMenu(menu_items)
enabled_func = function() enabled_func = function()
return not self.settings.disable_progress_bar return not self.settings.disable_progress_bar
end, end,
sub_item_table = { sub_item_table_func = function()
{ local common = {
text = _("No margins (0)"), {
checked_func = function() text = _("No margins (0)"),
return self.settings.progress_margin_width == Screen:scaleBySize(0) checked_func = function()
and not self.settings.progress_margin return self.settings.progress_margin_width == Screen:scaleBySize(0)
end, and not self.settings.progress_margin
callback = function() end,
self.settings.progress_margin_width = Screen:scaleBySize(0) callback = function()
self.settings.progress_margin = false self.settings.progress_margin_width = Screen:scaleBySize(0)
self:refreshFooter(true) self.settings.progress_margin = false
end, self:refreshFooter(true)
}, end,
{ },
text = _("Static margins (10)"), {
checked_func = function() text_func = function()
return self.settings.progress_margin_width == Screen:scaleBySize(10) if self.ui.document.info.has_pages then
and not self.settings.progress_margin return _("Same as book margins")
-- if same as book margins is selected in document with pages (pdf) we enforce static margins end
or (self.ui.document.info.has_pages and self.settings.progress_margin) return T(_("Same as book margins (%1)"), self.book_margins_footer_width)
end, end,
callback = function() checked_func = function()
self.settings.progress_margin_width = Screen:scaleBySize(10) return self.settings.progress_margin and not self.ui.document.info.has_pages
self.settings.progress_margin = false end,
self:refreshFooter(true) enabled_func = function()
end, return not self.ui.document.info.has_pages and self.settings.progress_bar_position ~= nil
}, end,
{ callback = function()
text_func = function() self.settings.progress_margin = true
if self.ui.document.info.has_pages then self.settings.progress_margin_width = Screen:scaleBySize(self.book_margins_footer_width)
return _("Same as book margins") self:refreshFooter(true)
end end
return T(_("Same as book margins (%1)"), self.book_margins_footer_width) },
end, }
checked_func = function() local function customMargin(px)
return self.settings.progress_margin and not self.ui.document.info.has_pages return {
end, text = T(_("Static margins (%1)"), px),
enabled_func = function() checked_func = function()
return not self.ui.document.info.has_pages and self.settings.progress_bar_position ~= nil return self.settings.progress_margin_width == Screen:scaleBySize(px)
end, and not self.settings.progress_margin
callback = function() -- if same as book margins is selected in document with pages (pdf) we enforce static margins
self.settings.progress_margin = true or (self.ui.document.info.has_pages and self.settings.progress_margin)
self.settings.progress_margin_width = Screen:scaleBySize(self.book_margins_footer_width) end,
self:refreshFooter(true) callback = function()
end self.settings.progress_margin_width = Screen:scaleBySize(px)
}, self.settings.progress_margin = false
}, self:refreshFooter(true)
end,
}
end
local device_defaults
if Device:isAndroid() then
device_defaults = customMargin(material_pixels)
else
device_defaults = customMargin(10)
end
table.insert(common, 2, device_defaults)
return common
end,
}, },
{ {
text_func = function() text_func = function()

Loading…
Cancel
Save