Page overlap: long-press to set as default (#8180)

Also deduplicate code out of ReaderPaging and ReaderRolling,
now in ReaderView and a specific menu module.
reviewable/pr8189/r1
hius07 3 years ago committed by GitHub
parent 3a677f40de
commit 0283c44ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -175,6 +175,9 @@ function ReaderMenu:setUpdateItemTable()
end
end
-- typeset tab
self.menu_items.page_overlap = require("ui/elements/page_overlap")
-- settings tab
-- insert common settings
for id, common_setting in pairs(dofile("frontend/ui/elements/common_settings_menu_table.lua")) do

@ -35,7 +35,6 @@ local ReaderPaging = InputContainer:new{
number_of_pages = 0,
visible_area = nil,
page_area = nil,
show_overlap_enable = nil,
overlap = Screen:scaleBySize(DOVERLAPPIXELS),
inverse_reading_order = nil,
@ -103,7 +102,6 @@ function ReaderPaging:init()
end
self.pan_interval = TimeVal:new{ usec = 1000000 / self.pan_rate }
self.number_of_pages = self.ui.document.info.number_of_pages
self.ui.menu:registerToMainMenu(self)
end
function ReaderPaging:onReaderReady()
@ -193,11 +191,6 @@ end
function ReaderPaging:onReadSettings(config)
self.page_positions = config:readSetting("page_positions") or {}
self:_gotoPage(config:readSetting("last_page") or 1)
if config:has("show_overlap_enable") then
self.show_overlap_enable = config:isTrue("show_overlap_enable")
else
self.show_overlap_enable = DSHOWOVERLAP
end
self.flipping_zoom_mode = config:readSetting("flipping_zoom_mode") or "page"
self.flipping_scroll_mode = config:isTrue("flipping_scroll_mode")
self.is_reflowed = config:has("kopt_text_wrap") and config:readSetting("kopt_text_wrap") == 1
@ -216,7 +209,6 @@ function ReaderPaging:onSaveSettings()
self.ui.doc_settings:saveSetting("page_positions", self.page_positions)
self.ui.doc_settings:saveSetting("last_page", self:getTopPage())
self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent())
self.ui.doc_settings:saveSetting("show_overlap_enable", self.show_overlap_enable)
self.ui.doc_settings:saveSetting("flipping_zoom_mode", self.flipping_zoom_mode)
self.ui.doc_settings:saveSetting("flipping_scroll_mode", self.flipping_scroll_mode)
self.ui.doc_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
@ -232,40 +224,6 @@ function ReaderPaging:getLastPercent()
end
end
function ReaderPaging:addToMainMenu(menu_items)
--- @fixme repeated code with page overlap menu for readerrolling
-- needs to keep only one copy of the logic as for the DRY principle.
-- The difference between the two menus is only the enabled func.
local page_overlap_menu = {
{
text = _("Page overlap"),
checked_func = function()
return self.show_overlap_enable
end,
callback = function()
self.show_overlap_enable = not self.show_overlap_enable
if not self.show_overlap_enable then
self.view.dim_area:clear()
end
end,
separator = true,
},
}
local overlap_enabled_func = function() return self.show_overlap_enable end
for _, menu_entry in ipairs(self.view:genOverlapStyleMenu(overlap_enabled_func)) do
table.insert(page_overlap_menu, menu_entry)
end
menu_items.page_overlap = {
text = _("Page overlap"),
enabled_func = function()
return not self.view.page_scroll
and (self.zoom_mode ~= "page" or (self.zoom_mode == "page" and self.is_reflowed))
and not self.zoom_mode:find("height")
end,
sub_item_table = page_overlap_menu,
}
end
function ReaderPaging:onColorRenderingUpdate()
self.ui.document:updateColorRendering()
UIManager:setDirty(self.view.dialog, "partial")
@ -1083,7 +1041,7 @@ function ReaderPaging:onGotoPageRel(diff)
self.view:PanningUpdate(panned_x, panned_y)
-- Update dim area in ReaderView
if self.show_overlap_enable then
if self.view.page_overlap_enable then
if self.current_page ~= old_page then
self.view.dim_area:clear()
else

@ -47,7 +47,6 @@ local ReaderRolling = InputContainer:new{
current_page= nil,
xpointer = nil,
panning_steps = ReaderPanning.panning_steps,
show_overlap_enable = nil,
cre_top_bar_enabled = false,
visible_pages = 1,
-- With visible_pages=2, in 2-pages mode, ensure the first
@ -209,11 +208,6 @@ function ReaderRolling:onReadSettings(config)
end
end
end
if config:has("show_overlap_enable") then
self.show_overlap_enable = config:isTrue("show_overlap_enable")
else
self.show_overlap_enable = DSHOWOVERLAP
end
if config:has("inverse_reading_order") then
self.inverse_reading_order = config:isTrue("inverse_reading_order")
@ -308,7 +302,6 @@ function ReaderRolling:onSaveSettings()
if self.ui.document then
self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent())
end
self.ui.doc_settings:saveSetting("show_overlap_enable", self.show_overlap_enable)
self.ui.doc_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
self.ui.doc_settings:saveSetting("visible_pages", self.visible_pages)
self.ui.doc_settings:saveSetting("hide_nonlinear_flows", self.hide_nonlinear_flows)
@ -398,64 +391,6 @@ function ReaderRolling:getLastProgress()
end
function ReaderRolling:addToMainMenu(menu_items)
--- @fixme repeated code with page overlap menu for readerpaging
-- needs to keep only one copy of the logic as for the DRY principle.
-- The difference between the two menus is only the enabled func.
local overlap_lines_help_text = _([[
When page overlap is enabled, some lines from the previous page will be displayed on the next page.
You can set how many lines are shown.]])
local page_overlap_menu = {
{
text = _("Page overlap"),
checked_func = function()
return self.show_overlap_enable
end,
callback = function()
self.show_overlap_enable = not self.show_overlap_enable
if not self.show_overlap_enable then
self.view.dim_area:clear()
end
end
},
{
text_func = function()
return T(_("Number of lines: %1"), G_reader_settings:readSetting("copt_overlap_lines") or 1)
end,
enabled_func = function()
return self.show_overlap_enable
end,
callback = function(touchmenu_instance)
local SpinWidget = require("ui/widget/spinwidget")
UIManager:show(SpinWidget:new{
width = math.floor(Screen:getWidth() * 0.75),
value = G_reader_settings:readSetting("copt_overlap_lines") or 1,
value_min = 1,
value_max = 10,
precision = "%d",
ok_text = _("Set"),
title_text = _("Set overlapped lines"),
info_text = overlap_lines_help_text,
callback = function(spin)
G_reader_settings:saveSetting("copt_overlap_lines", spin.value)
touchmenu_instance:updateItems()
end,
})
end,
keep_menu_open = true,
help_text = overlap_lines_help_text,
separator = true,
},
}
local overlap_enabled_func = function() return self.show_overlap_enable end
for _, menu_entry in ipairs(self.view:genOverlapStyleMenu(overlap_enabled_func)) do
table.insert(page_overlap_menu, menu_entry)
end
menu_items.page_overlap = {
text = _("Page overlap"),
enabled_func = function() return self.view.view_mode ~= "page" end,
help_text = _([[When page overlap is enabled, some lines from the previous pages are shown on the next page.]]),
sub_item_table = page_overlap_menu,
}
if self.ui.document:hasNonLinearFlows() then
local hide_nonlinear_text = _("When hide non-linear fragments is enabled, any non-linear fragments will be hidden from the normal page flow. Such fragments will always remain accessible through links, the table of contents and the 'Go to' dialog. This only works in single-page mode.")
menu_items.hide_nonlinear_flows = {
@ -878,7 +813,7 @@ function ReaderRolling:onGotoViewRel(diff)
local footer_height = ((self.view.footer_visible and not self.view.footer.settings.reclaim_height) and 1 or 0) * self.view.footer:getHeight()
local page_visible_height = self.ui.dimen.h - footer_height
local pan_diff = diff * page_visible_height
if self.show_overlap_enable then
if self.view.page_overlap_enable then
local overlap_lines = G_reader_settings:readSetting("copt_overlap_lines") or 1
local overlap_h = Screen:scaleBySize(self.ui.font.font_size * 1.1 * self.ui.font.line_space_percent/100.0) * overlap_lines
if pan_diff > overlap_h then
@ -1067,7 +1002,7 @@ function ReaderRolling:_gotoPos(new_pos, do_dim_area)
local max_pos = self.ui.document.info.doc_height - self.ui.dimen.h + self.view.footer:getHeight()
if new_pos > max_pos then new_pos = max_pos end
-- adjust dim_area according to new_pos
if self.view.view_mode ~= "page" and self.show_overlap_enable and do_dim_area then
if self.view.view_mode ~= "page" and self.view.page_overlap_enable and do_dim_area then
local footer_height = ((self.view.footer_visible and not self.view.footer.settings.reclaim_height) and 1 or 0) * self.view.footer:getHeight()
local page_visible_height = self.ui.dimen.h - footer_height
local panned_step = new_pos - self.current_pos

@ -3,7 +3,6 @@ ReaderView module handles all the screen painting for document browsing.
]]
local Blitbuffer = require("ffi/blitbuffer")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Geom = require("ui/geometry")
local Event = require("ui/event")
@ -179,7 +178,7 @@ function ReaderView:paintTo(bb, x, y)
end
-- dim last read area
if not self.dim_area:isEmpty() then
if not self.dim_area:isEmpty() and self:isOverlapAllowed() then
if self.page_overlap_style == "dim" then
bb:dimRect(
self.dim_area.x, self.dim_area.y,
@ -790,6 +789,7 @@ function ReaderView:onReadSettings(config)
local page_scroll = config:readSetting("kopt_page_scroll") or self.document.configurable.page_scroll
self.page_scroll = page_scroll == 1 and true or false
self.highlight.saved = config:readSetting("highlight") or {}
self.page_overlap_enable = config:isTrue("show_overlap_enable") or G_reader_settings:isTrue("page_overlap_enable") or DSHOWOVERLAP
self.page_overlap_style = config:readSetting("page_overlap_style") or G_reader_settings:readSetting("page_overlap_style") or "dim"
self.page_gap.height = Screen:scaleBySize(config:readSetting("kopt_page_gap_height")
or G_reader_settings:readSetting("kopt_page_gap_height")
@ -904,6 +904,7 @@ function ReaderView:onSaveSettings()
end
self.ui.doc_settings:saveSetting("gamma", self.state.gamma)
self.ui.doc_settings:saveSetting("highlight", self.highlight.saved)
self.ui.doc_settings:saveSetting("show_overlap_enable", self.page_overlap_enable)
self.ui.doc_settings:saveSetting("page_overlap_style", self.page_overlap_style)
end
@ -930,43 +931,6 @@ function ReaderView:getRenderModeMenuTable()
}
end
local page_overlap_styles = {
arrow = _("Arrow"),
dim = _("Gray out"),
}
function ReaderView:genOverlapStyleMenu(overlap_enabled_func)
local view = self
local get_overlap_style = function(style)
return {
text = page_overlap_styles[style],
enabled_func = overlap_enabled_func,
checked_func = function()
return view.page_overlap_style == style
end,
callback = function()
view.page_overlap_style = style
end,
hold_callback = function()
UIManager:show(ConfirmBox:new{
text = T(
_("Set default overlap style to %1?"),
style
),
ok_callback = function()
view.page_overlap_style = style
G_reader_settings:saveSetting("page_overlap_style", style)
end,
})
end,
}
end
return {
get_overlap_style("arrow"),
get_overlap_style("dim"),
}
end
function ReaderView:onCloseDocument()
self.hinting = false
-- stop any in fly HintPage event
@ -1004,4 +968,15 @@ function ReaderView:checkAutoSaveSettings()
end
end
function ReaderView:isOverlapAllowed()
if self.ui.document.info.has_pages then
return not self.page_scroll
and (self.ui.paging.zoom_mode ~= "page"
or (self.ui.paging.zoom_mode == "page" and self.ui.paging.is_reflowed))
and not self.ui.paging.zoom_mode:find("height")
else
return self.view_mode ~= "page"
end
end
return ReaderView

@ -0,0 +1,104 @@
local Device = require("device")
local ReaderUI = require("apps/reader/readerui")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local Screen = Device.screen
local T = require("ffi/util").template
local PageOverlap = {
text = _("Page overlap"),
sub_item_table = {
{
text_func = function()
local text = _("Page overlap")
if G_reader_settings:isTrue("page_overlap_enable") then
text = text .. ""
end
return text
end,
checked_func = function()
return ReaderUI.instance.view:isOverlapAllowed() and ReaderUI.instance.view.page_overlap_enable
end,
callback = function()
local view = ReaderUI.instance.view
if view:isOverlapAllowed() then
if view.page_overlap_enable then
view.dim_area:clear()
end
view.page_overlap_enable = not view.page_overlap_enable
else
UIManager:show(require("ui/widget/infomessage"):new{
text = _("Page overlap cannot be enabled in the current view mode."),
timeout = 2,
})
end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:flipNilOrFalse("page_overlap_enable")
touchmenu_instance:updateItems()
end,
},
}
}
table.insert(PageOverlap.sub_item_table, {
keep_menu_open = true,
text_func = function()
return T(_("Number of lines: %1"), G_reader_settings:readSetting("copt_overlap_lines") or 1)
end,
enabled_func = function()
return not ReaderUI.instance.document.info.has_pages and
ReaderUI.instance.view:isOverlapAllowed() and ReaderUI.instance.view.page_overlap_enable
end,
callback = function(touchmenu_instance)
local SpinWidget = require("ui/widget/spinwidget")
UIManager:show(SpinWidget:new{
title_text = _("Number of overlapped lines"),
info_text = _([[
When page overlap is enabled, some lines from the previous page will be displayed on the next page.
You can set how many lines are shown.]]),
width = math.floor(Screen:getWidth() * 0.75),
value = G_reader_settings:readSetting("copt_overlap_lines") or 1,
value_min = 1,
value_max = 10,
default_value = 1,
precision = "%d",
callback = function(spin)
G_reader_settings:saveSetting("copt_overlap_lines", spin.value)
touchmenu_instance:updateItems()
end,
})
end,
separator = true,
})
local page_overlap_styles = {
arrow = _("Arrow"),
dim = _("Gray out"),
}
for k, v in pairs(page_overlap_styles) do
table.insert(PageOverlap.sub_item_table, {
text_func = function()
local text = v
if G_reader_settings:readSetting("page_overlap_style") == k then
text = text .. ""
end
return text
end,
enabled_func = function()
return ReaderUI.instance.view:isOverlapAllowed() and ReaderUI.instance.view.page_overlap_enable
end,
checked_func = function()
return ReaderUI.instance.view.page_overlap_style == k
end,
callback = function()
ReaderUI.instance.view.page_overlap_style = k
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("page_overlap_style", k)
touchmenu_instance:updateItems()
end,
})
end
return PageOverlap
Loading…
Cancel
Save