diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 1215ae135..91481a6af 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -792,7 +792,7 @@ function ReaderView:onReadSettings(config) self.highlight.saved = config:readSetting("highlight", {}) -- Highlight formats in crengine and mupdf are incompatible. -- Backup highlights when the document is opened with incompatible engine. - local _page, page_highlights = next(self.highlight.saved) + local _, page_highlights = next(self.highlight.saved) -- get the first page with highlights if page_highlights then local highlight_type = type(page_highlights[1].pos0) if self.ui.rolling and highlight_type == "table" then @@ -1007,13 +1007,17 @@ function ReaderView:isOverlapAllowed() end end -function ReaderView:onToggleReadingOrder() - self.inverse_reading_order = not self.inverse_reading_order - if self.ui.document.info.has_pages then - self.ui.paging:setupTouchZones() - else +function ReaderView:setupTouchZones() + if self.ui.rolling then self.ui.rolling:setupTouchZones() + else + self.ui.paging:setupTouchZones() end +end + +function ReaderView:onToggleReadingOrder() + self.inverse_reading_order = not self.inverse_reading_order + self:setupTouchZones() local is_rtl = self.inverse_reading_order ~= BD.mirroredUILayout() -- mirrored reading UIManager:show(Notification:new{ text = is_rtl and _("RTL page turning.") or _("LTR page turning."), @@ -1022,14 +1026,40 @@ function ReaderView:onToggleReadingOrder() end function ReaderView:getTapZones() - local forward_zone = { - ratio_x = DTAP_ZONE_FORWARD.x, ratio_y = DTAP_ZONE_FORWARD.y, - ratio_w = DTAP_ZONE_FORWARD.w, ratio_h = DTAP_ZONE_FORWARD.h, - } - local backward_zone = { - ratio_x = DTAP_ZONE_BACKWARD.x, ratio_y = DTAP_ZONE_BACKWARD.y, - ratio_w = DTAP_ZONE_BACKWARD.w, ratio_h = DTAP_ZONE_BACKWARD.h, - } + local forward_zone, backward_zone + local tap_zones_type = G_reader_settings:readSetting("page_turns_tap_zones", "default") + if tap_zones_type == "default" then + forward_zone = { + ratio_x = DTAP_ZONE_FORWARD.x, ratio_y = DTAP_ZONE_FORWARD.y, + ratio_w = DTAP_ZONE_FORWARD.w, ratio_h = DTAP_ZONE_FORWARD.h, + } + backward_zone = { + ratio_x = DTAP_ZONE_BACKWARD.x, ratio_y = DTAP_ZONE_BACKWARD.y, + ratio_w = DTAP_ZONE_BACKWARD.w, ratio_h = DTAP_ZONE_BACKWARD.h, + } + else -- user defined page turns tap zones + local tap_zone_forward_w = G_reader_settings:readSetting("page_turns_tap_zone_forward_size_ratio", DTAP_ZONE_FORWARD.w) + local tap_zone_backward_w = 1 - tap_zone_forward_w + if tap_zones_type == "left_right" then + forward_zone = { + ratio_x = tap_zone_backward_w, ratio_y = 0, + ratio_w = tap_zone_forward_w, ratio_h = 1, + } + backward_zone = { + ratio_x = 0, ratio_y = 0, + ratio_w = tap_zone_backward_w, ratio_h = 1, + } + else + forward_zone = { + ratio_x = 0, ratio_y = tap_zone_backward_w, + ratio_w = 1, ratio_h = tap_zone_forward_w, + } + backward_zone = { + ratio_x = 0, ratio_y = 0, + ratio_w = 1, ratio_h = tap_zone_backward_w, + } + end + end if self.inverse_reading_order ~= BD.mirroredUILayout() then -- mirrored reading forward_zone.ratio_x = 1 - forward_zone.ratio_x - forward_zone.ratio_w backward_zone.ratio_x = 1 - backward_zone.ratio_x - backward_zone.ratio_w diff --git a/frontend/ui/elements/page_turns.lua b/frontend/ui/elements/page_turns.lua index 36373b0a0..ba395fb53 100644 --- a/frontend/ui/elements/page_turns.lua +++ b/frontend/ui/elements/page_turns.lua @@ -1,7 +1,58 @@ local Device = require("device") local Event = require("ui/event") +local ReaderUI = require("apps/reader/readerui") local UIManager = require("ui/uimanager") local _ = require("gettext") +local T = require("ffi/util").template + +local page_turns_tap_zones_sub_items = {} -- build the Tap zones submenu +local tap_zones = { + default = _("Default"), + left_right = _("Left/right"), + top_bottom = _("Top/bottom"), +} +local function genTapZonesMenu(tap_zones_type) + table.insert(page_turns_tap_zones_sub_items, { + text = tap_zones[tap_zones_type], + checked_func = function() + return G_reader_settings:readSetting("page_turns_tap_zones", "default") == tap_zones_type + end, + callback = function() + G_reader_settings:saveSetting("page_turns_tap_zones", tap_zones_type) + ReaderUI.instance.view:setupTouchZones() + end, + }) +end +genTapZonesMenu("default") +genTapZonesMenu("left_right") +genTapZonesMenu("top_bottom") +table.insert(page_turns_tap_zones_sub_items, { + text_func = function() + local size = math.floor(G_reader_settings:readSetting("page_turns_tap_zone_forward_size_ratio", DTAP_ZONE_FORWARD.w) * 100) + return T(_("Forward tap zone size: %1%"), size) + end, + enabled_func = function() + return G_reader_settings:readSetting("page_turns_tap_zones", "default") ~= "default" + end, + keep_menu_open = true, + callback = function(touchmenu_instance) + local is_left_right = G_reader_settings:readSetting("page_turns_tap_zones") == "left_right" + local size = math.floor(G_reader_settings:readSetting("page_turns_tap_zone_forward_size_ratio", DTAP_ZONE_FORWARD.w) * 100) + UIManager:show(require("ui/widget/spinwidget"):new{ + title_text = is_left_right and _("Forward tap zone width") or _("Forward tap zone height"), + info_text = is_left_right and _("Percentage of screen width") or _("Percentage of screen height"), + value = size, + value_min = 0, + value_max = 100, + default_value = math.floor(DTAP_ZONE_FORWARD.w * 100), + callback = function(spin) + G_reader_settings:saveSetting("page_turns_tap_zone_forward_size_ratio", spin.value / 100) + ReaderUI.instance.view:setupTouchZones() + if touchmenu_instance then touchmenu_instance:updateItems() end + end, + }) + end, +}) local PageTurns = { text = _("Page turns"), @@ -23,6 +74,16 @@ local PageTurns = { callback = function() G_reader_settings:flipNilOrFalse("page_turns_disable_swipe") end, + }, + { + text_func = function() + local tap_zones_type = G_reader_settings:readSetting("page_turns_tap_zones", "default") + return T(_("Tap zones: %1"), tap_zones[tap_zones_type]:lower()) + end, + enabled_func = function() + return G_reader_settings:nilOrFalse("page_turns_disable_tap") + end, + sub_item_table = page_turns_tap_zones_sub_items, separator = true, }, { @@ -34,8 +95,7 @@ local PageTurns = { return text end, checked_func = function() - local ui = require("apps/reader/readerui"):_getRunningInstance() - return ui.view.inverse_reading_order + return ReaderUI.instance.view.inverse_reading_order end, callback = function() UIManager:broadcastEvent(Event:new("ToggleReadingOrder")) @@ -78,4 +138,5 @@ if Device:hasKeys() then end, }) end + return PageTurns