cre landscape view: adds 1 page / 2 pages toggable

Adds a toggle switch in the Orientation bottom config menu to
allow showing 1 page or 2 pages when in landscape mode.
Previously, this was hardcoded to be in 2-pages modes only
in some circumstances (device resolution + user dpi).
pull/4786/head
poire-z 5 years ago
parent 0948a4b656
commit 22bc9dacb5

@ -43,6 +43,11 @@ local ReaderRolling = InputContainer:new{
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
-- page is always odd or even (odd is logical to avoid a
-- same page when turning first 2-pages set of document)
odd_or_even_first_page = 1 -- 1 = odd, 2 = even, nil or others = free
}
function ReaderRolling:init()
@ -182,6 +187,16 @@ function ReaderRolling:onReadSettings(config)
self.show_overlap_enable = DSHOWOVERLAP
end
self.inverse_reading_order = config:readSetting("inverse_reading_order") or false
-- This self.visible_pages may not be the current nb of visible pages
-- as crengine may decide to not ensure that in some conditions.
-- It's the one we got from settings, the one the user has decided on
-- with config toggle, and the one that we will save for next load.
-- Use self.ui.document:getVisiblePageCount() to get the current
-- crengine used value.
self.visible_pages = config:readSetting("visible_pages") or
G_reader_settings:readSetting("copt_visible_pages") or 1
self.ui.document:setVisiblePageCount(self.visible_pages)
end
-- in scroll mode percent_finished must be save before close document
@ -228,6 +243,7 @@ function ReaderRolling:onSaveSettings()
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)
end
function ReaderRolling:onReaderReady()
@ -741,7 +757,21 @@ function ReaderRolling:_gotoPercent(new_percent)
self:_gotoPos(new_percent * self.ui.document.info.doc_height / 10000)
end
function ReaderRolling:_gotoPage(new_page)
function ReaderRolling:_gotoPage(new_page, free_first_page)
if self.ui.document:getVisiblePageCount() > 1 and not free_first_page then
-- Ensure we always have the first of the two pages odd
if self.odd_or_even_first_page == 1 then -- odd
if new_page % 2 == 0 then
-- requested page will be shown as the right page
new_page = new_page - 1
end
elseif self.odd_or_even_first_page == 2 then -- (or 'even' if requested)
if new_page % 2 == 1 then
-- requested page will be shown as the right page
new_page = new_page - 1
end
end
end
self.ui.document:gotoPage(new_page)
if self.view.view_mode == "page" then
self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getCurrentPage()))
@ -768,6 +798,26 @@ function ReaderRolling:updatePageLink()
end
--]]
function ReaderRolling:onSetVisiblePages(visible_pages)
-- crengine may decide to not ensure the value we request
-- (for example, in 2-pages mode, it may stop being ensured
-- when we increase the font size up to a point where a line
-- would contain less that 20 glyphs).
-- crengine may enforce visible_page=1 when:
-- - not in page mode but in scroll mode
-- - screen w/h < 6/5
-- - w < 20*em
-- We nevertheless update the setting (that will saved) with what
-- the user has requested - and not what crengine has enforced.
self.visible_pages = visible_pages
local prev_visible_pages = self.ui.document:getVisiblePageCount()
self.ui.document:setVisiblePageCount(visible_pages)
local cur_visible_pages = self.ui.document:getVisiblePageCount()
if cur_visible_pages ~= prev_visible_pages then
self.ui:handleEvent(Event:new("UpdatePos"))
end
end
function ReaderRolling:onSetStatusLine(status_line, on_read_settings)
-- status_line values:
-- in crengine: 0=header enabled, 1=disabled

@ -190,11 +190,12 @@ end
function CreDocument:render()
-- load document before rendering
self:loadDocument()
-- set visible page count in landscape
if math.max(CanvasContext:getWidth(), CanvasContext:getHeight()) / CanvasContext:getDPI()
< DCREREADER_TWO_PAGE_THRESHOLD then
self:setVisiblePageCount(1)
end
-- This is now configurable and done by ReaderRolling:
-- -- set visible page count in landscape
-- if math.max(CanvasContext:getWidth(), CanvasContext:getHeight()) / CanvasContext:getDPI()
-- < DCREREADER_TWO_PAGE_THRESHOLD then
-- self:setVisiblePageCount(1)
-- end
logger.dbg("CreDocument: rendering document...")
self._document:renderDocument()
self.info.doc_height = self._document:getFullHeight()

@ -29,7 +29,32 @@ local CreOptions = {
current_func = function() return Device.screen:getScreenMode() end,
event = "ChangeScreenMode",
name_text_hold_callback = optionsutil.showValues,
}
},
{
name = "visible_pages",
name_text = S.TWO_PAGES,
toggle = {S.OFF, S.ON},
values = {1, 2},
default_value = 1,
args = {1, 2},
default_arg = 1,
event = "SetVisiblePages",
current_func = function()
-- If not in landscape mode, shows "1" as selected
if Device.screen:getScreenMode() ~= "landscape" then
return 1
end
-- if we return nil, ConfigDialog will pick the one from the
-- configurable as if we hadn't provided this 'current_func'
end,
enabled_func = function(configurable)
return Device.screen:getScreenMode() == "landscape" and
optionsutil.enableIfEquals(configurable, "view_mode", 0) -- "page"
end,
name_text_hold_callback = optionsutil.showValues,
help_text = _([[In landscape mode, you can choose to display one or two pages of the book on the screen.
Note that this may not be ensured under some conditions: in scroll mode, when a very big font size is used, or on devices with a very low aspect ratio.]]),
},
}
},
{

@ -3,6 +3,7 @@ local _ = require("gettext")
local S = {}
S.SCREEN_MODE = _("Orientation")
S.TWO_PAGES = _("Two Pages")
S.PAGE_CROP = _("Page Crop")
S.FULL_SCREEN = _("Full Screen")
S.SCROLL_MODE = _("Scroll Mode")

Loading…
Cancel
Save