Page overlap menu (cre): set nb of overlap lines (#4538)

Make this existing setting tunable with a menu item.
Also make the Page overlap and Highlight menus use a
checkbox, and their items grayed out when disabled.
pull/4545/head
poire-z 5 years ago committed by GitHub
parent 27b6c1546a
commit 895589ddaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -100,8 +100,9 @@ function ReaderHighlight:genHighlightDrawerMenu()
end end
return { return {
{ {
text_func = function() text = _("Allow highlighting"),
return self.view.highlight.disabled and _("Enable") or _("Disable") checked_func = function()
return not self.view.highlight.disabled
end, end,
callback = function() callback = function()
self.view.highlight.disabled = not self.view.highlight.disabled self.view.highlight.disabled = not self.view.highlight.disabled
@ -109,6 +110,7 @@ function ReaderHighlight:genHighlightDrawerMenu()
hold_callback = function(touchmenu_instance) hold_callback = function(touchmenu_instance)
self:makeDefault(not self.view.highlight.disabled) self:makeDefault(not self.view.highlight.disabled)
end, end,
separator = true,
}, },
get_highlight_style("lighten"), get_highlight_style("lighten"),
get_highlight_style("underscore"), get_highlight_style("underscore"),

@ -187,18 +187,21 @@ function ReaderPaging:addToMainMenu(menu_items)
-- The difference between the two menus is only the enabled func. -- The difference between the two menus is only the enabled func.
local page_overlap_menu = { local page_overlap_menu = {
{ {
text_func = function() text = _("Page overlap"),
return self.show_overlap_enable and _("Disable") or _("Enable") checked_func = function()
return self.show_overlap_enable
end, end,
callback = function() callback = function()
self.show_overlap_enable = not self.show_overlap_enable self.show_overlap_enable = not self.show_overlap_enable
if not self.show_overlap_enable then if not self.show_overlap_enable then
self.view:resetDimArea() self.view:resetDimArea()
end end
end end,
separator = true,
}, },
} }
for _, menu_entry in ipairs(self.view:genOverlapStyleMenu()) do 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) table.insert(page_overlap_menu, menu_entry)
end end
menu_items.page_overlap = { menu_items.page_overlap = {

@ -9,6 +9,7 @@ local logger = require("logger")
local _ = require("gettext") local _ = require("gettext")
local Input = Device.input local Input = Device.input
local Screen = Device.screen local Screen = Device.screen
local T = require("ffi/util").template
--[[ --[[
Rolling is just like paging in page-based documents except that Rolling is just like paging in page-based documents except that
@ -42,8 +43,6 @@ local ReaderRolling = InputContainer:new{
xpointer = nil, xpointer = nil,
panning_steps = ReaderPanning.panning_steps, panning_steps = ReaderPanning.panning_steps,
show_overlap_enable = nil, show_overlap_enable = nil,
-- nb of lines from previous page to show on next page (scroll mode only)
overlap_lines = G_reader_settings:readSetting("copt_overlap_lines") or 1,
cre_top_bar_enabled = false, cre_top_bar_enabled = false,
} }
@ -311,10 +310,14 @@ function ReaderRolling:addToMainMenu(menu_items)
-- FIXME: repeated code with page overlap menu for readerpaging -- FIXME: repeated code with page overlap menu for readerpaging
-- needs to keep only one copy of the logic as for the DRY principle. -- 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. -- 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 = { local page_overlap_menu = {
{ {
text_func = function() text = _("Page overlap"),
return self.show_overlap_enable and _("Disable") or _("Enable") checked_func = function()
return self.show_overlap_enable
end, end,
callback = function() callback = function()
self.show_overlap_enable = not self.show_overlap_enable self.show_overlap_enable = not self.show_overlap_enable
@ -323,13 +326,43 @@ function ReaderRolling:addToMainMenu(menu_items)
end end
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 = 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"),
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,
},
} }
for _, menu_entry in ipairs(self.view:genOverlapStyleMenu()) do 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) table.insert(page_overlap_menu, menu_entry)
end end
menu_items.page_overlap = { menu_items.page_overlap = {
text = _("Page overlap"), text = _("Page overlap"),
enabled_func = function() return self.view.view_mode ~= "page" end, 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, sub_item_table = page_overlap_menu,
} }
end end
@ -525,7 +558,8 @@ function ReaderRolling:onGotoViewRel(diff)
local page_visible_height = self.ui.dimen.h - footer_height local page_visible_height = self.ui.dimen.h - footer_height
local pan_diff = diff * page_visible_height local pan_diff = diff * page_visible_height
if self.show_overlap_enable then if self.show_overlap_enable then
local overlap_h = Screen:scaleBySize(self.ui.font.font_size * 1.1 * self.ui.font.line_space_percent/100.0) * self.overlap_lines 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 if pan_diff > overlap_h then
pan_diff = pan_diff - overlap_h pan_diff = pan_diff - overlap_h
elseif pan_diff < -overlap_h then elseif pan_diff < -overlap_h then

@ -841,11 +841,12 @@ local page_overlap_styles = {
dim = _("Gray out"), dim = _("Gray out"),
} }
function ReaderView:genOverlapStyleMenu() function ReaderView:genOverlapStyleMenu(overlap_enabled_func)
local view = self local view = self
local get_overlap_style = function(style) local get_overlap_style = function(style)
return { return {
text = page_overlap_styles[style], text = page_overlap_styles[style],
enabled_func = overlap_enabled_func,
checked_func = function() checked_func = function()
return view.page_overlap_style == style return view.page_overlap_style == style
end, end,

Loading…
Cancel
Save