From 4d67dd59cab50641878106a3e15f430942613bd0 Mon Sep 17 00:00:00 2001 From: poire-z Date: Tue, 15 Jan 2019 18:38:23 +0100 Subject: [PATCH] Rationalize Links> menu items - Remove duplicated "Show footnote popup". Have the same setting applied for Tap or 'Swipe to follow nearest link'. - Make some menu items enabled or disabled depending on if they would have some effect with the current state of other menu items, as some kind of visual self-documentation of these dependancies. - Add menu item to set the footnote popup font size, relative to the book font size. - SpinWidget: allow for showing some informative text --- frontend/apps/reader/modules/readerlink.lua | 89 ++++++++++++++------- frontend/ui/widget/footnotewidget.lua | 2 +- frontend/ui/widget/spinwidget.lua | 54 ++++++++----- 3 files changed, 95 insertions(+), 50 deletions(-) diff --git a/frontend/apps/reader/modules/readerlink.lua b/frontend/apps/reader/modules/readerlink.lua index 93ed575b5..f9b432dd1 100644 --- a/frontend/apps/reader/modules/readerlink.lua +++ b/frontend/apps/reader/modules/readerlink.lua @@ -33,6 +33,13 @@ function ReaderLink:init() -- For relative local file links local directory, filename = util.splitFilePathName(self.ui.document.file) -- luacheck: no unused self.document_dir = directory + -- Migrate these old settings to the new common one + if G_reader_settings:isTrue("tap_link_footnote_popup") + or G_reader_settings:isTrue("swipe_link_footnote_popup") then + G_reader_settings:saveSetting("tap_link_footnote_popup", nil) + G_reader_settings:saveSetting("swipe_link_footnote_popup", nil) + G_reader_settings:saveSetting("footnote_link_in_popup", true) + end end function ReaderLink:onReadSettings(config) @@ -79,8 +86,8 @@ local function isTapIgnoreExternalLinksEnabled() return G_reader_settings:isTrue("tap_ignore_external_links") end -local function isTapLinkFootnotePopupEnabled() - return G_reader_settings:isTrue("tap_link_footnote_popup") +local function isFootnoteLinkInPopupEnabled() + return G_reader_settings:isTrue("footnote_link_in_popup") end local function isPreferFootnoteEnabled() @@ -99,10 +106,6 @@ local function isSwipeToFollowNearestLinkEnabled() return G_reader_settings:isTrue("swipe_to_follow_nearest_link") end -local function isSwipeLinkFootnotePopupEnabled() - return G_reader_settings:isTrue("swipe_link_footnote_popup") -end - local function isSwipeToJumpToLatestBookmarkEnabled() return G_reader_settings:isTrue("swipe_to_jump_to_latest_bookmark") end @@ -176,17 +179,11 @@ If any of the other Swipe to follow link options is enabled, this will work only -- followed a link, than on EPUB, it's safer to not use them on PDF documents -- even if the user enabled these features for EPUB documents). if not self.ui.document.info.has_pages then - local footnote_popup_help_text = _([[ -Show internal link target content in a footnote popup when it looks like it might be a footnote, instead of following the link. - -Note that depending on the book quality, footnote detection may not always work correctly. -The footnote content may be empty, truncated, or include other footnotes. - -From the footnote popup, you can jump to the footnote location in the book by swiping to the left.]]) -- Tap section menu_items.follow_links.sub_item_table[1].separator = nil table.insert(menu_items.follow_links.sub_item_table, 2, { text = _("Allow larger tap area around links"), + enabled_func = isTapToFollowLinksOn, checked_func = isLargerTapAreaToFollowLinksEnabled, callback = function() G_reader_settings:saveSetting("larger_tap_area_to_follow_links", @@ -196,6 +193,7 @@ From the footnote popup, you can jump to the footnote location in the book by sw }) table.insert(menu_items.follow_links.sub_item_table, 3, { text = _("Ignore external links"), + enabled_func = isTapToFollowLinksOn, checked_func = isTapIgnoreExternalLinksEnabled, callback = function() G_reader_settings:saveSetting("tap_ignore_external_links", @@ -203,38 +201,69 @@ From the footnote popup, you can jump to the footnote location in the book by sw end, help_text = _([[Ignore taps on external links. Useful with Wikipedia EPUBs to make page turning easier. You can still follow them from the dictionary window or the selection menu after holding on them.]]), + separator = true, }) table.insert(menu_items.follow_links.sub_item_table, 4, { text = _("Show footnotes in popup"), - checked_func = isTapLinkFootnotePopupEnabled, + enabled_func = function() + return isTapToFollowLinksOn() or isSwipeToFollowNearestLinkEnabled() + end, + checked_func = isFootnoteLinkInPopupEnabled, callback = function() - G_reader_settings:saveSetting("tap_link_footnote_popup", - not isTapLinkFootnotePopupEnabled()) + G_reader_settings:saveSetting("footnote_link_in_popup", + not isFootnoteLinkInPopupEnabled()) end, - help_text = footnote_popup_help_text, - separator = true, + help_text = _([[ +Show internal link target content in a footnote popup when it looks like it might be a footnote, instead of following the link. + +Note that depending on the book quality, footnote detection may not always work correctly. +The footnote content may be empty, truncated, or include other footnotes. + +From the footnote popup, you can jump to the footnote location in the book by swiping to the left.]]), }) table.insert(menu_items.follow_links.sub_item_table, 5, { text = _("Show more links as footnotes"), + enabled_func = function() + return isFootnoteLinkInPopupEnabled() and + (isTapToFollowLinksOn() or isSwipeToFollowNearestLinkEnabled()) + end, checked_func = isPreferFootnoteEnabled, callback = function() G_reader_settings:saveSetting("link_prefer_footnote", not isPreferFootnoteEnabled()) end, help_text = _([[Loosen footnote detection rules to show more links as footnotes.]]), - separator = true, }) - -- Swipe section - menu_items.follow_links.sub_item_table[8].separator = nil - table.insert(menu_items.follow_links.sub_item_table, 9, { - text = _("Swipe to show footnotes in popup"), - checked_func = isSwipeLinkFootnotePopupEnabled, - enabled_func = isSwipeToFollowNearestLinkEnabled, + table.insert(menu_items.follow_links.sub_item_table, 6, { + text = _("Set footnote popup font size"), + enabled_func = function() + return isFootnoteLinkInPopupEnabled() and + (isTapToFollowLinksOn() or isSwipeToFollowNearestLinkEnabled()) + end, + keep_menu_open = true, callback = function() - G_reader_settings:saveSetting("swipe_link_footnote_popup", - not isSwipeLinkFootnotePopupEnabled()) + local SpinWidget = require("ui/widget/spinwidget") + UIManager:show(SpinWidget:new{ + width = Screen:getWidth() * 0.75, + value = G_reader_settings:readSetting("footnote_popup_relative_font_size") or -2, + value_min = -10, + value_max = 5, + precision = "%+d", + ok_text = _("Set font size"), + title_text = _("Set footnote popup font size"), + text = _([[ +The footnote popup font adjusts to the font size you've set for the document. +You can specify here how much smaller or larger it should be relative to the document font size. +A negative value will make it smaller, while a positive one will make it larger. +The recommended value is -2.]]), + callback = function(spin) + G_reader_settings:saveSetting("footnote_popup_relative_font_size", spin.value) + end, + }) end, - help_text = footnote_popup_help_text, + help_text = _([[ +The footnote popup font adjusts to the font size you've set for the document. +This allows you to specify how much smaller or larger it should be relative to the document font size.]]), separator = true, }) end @@ -376,7 +405,7 @@ function ReaderLink:onTap(_, ges) end return end - local allow_footnote_popup = isTapLinkFootnotePopupEnabled() + local allow_footnote_popup = isFootnoteLinkInPopupEnabled() -- If tap_ignore_external_links, skip precise tap detection to really -- ignore a tap on an external link, and allow using onGoToPageLink() -- to find the nearest internal link @@ -627,7 +656,7 @@ function ReaderLink:onSwipe(arg, ges) -- no sense allowing footnote popup if first link ret = self:onGoToPageLink(ges, true) elseif isSwipeToFollowNearestLinkEnabled() then - local allow_footnote_popup = isSwipeLinkFootnotePopupEnabled() + local allow_footnote_popup = isFootnoteLinkInPopupEnabled() ret = self:onGoToPageLink(ges, false, allow_footnote_popup) end -- If no link found, or no follow link option enabled, diff --git a/frontend/ui/widget/footnotewidget.lua b/frontend/ui/widget/footnotewidget.lua index af91db8e6..664c2c5fe 100644 --- a/frontend/ui/widget/footnotewidget.lua +++ b/frontend/ui/widget/footnotewidget.lua @@ -178,7 +178,7 @@ function FootnoteWidget:init() -- We may use a font size a bit smaller than the document one (because -- footnotes are usually smaller, and because NotoSans is a bit on the -- larger size when compared to other fonts at the same size) - local font_size = self.doc_font_size - 2 + local font_size = self.doc_font_size + (G_reader_settings:readSetting("footnote_popup_relative_font_size") or -2) -- We want to display the footnote text with the same margins as -- the document, but keep the scrollbar in the right margin, so diff --git a/frontend/ui/widget/spinwidget.lua b/frontend/ui/widget/spinwidget.lua index 42a7a9ae6..cfe80bdfc 100644 --- a/frontend/ui/widget/spinwidget.lua +++ b/frontend/ui/widget/spinwidget.lua @@ -13,6 +13,7 @@ local LineWidget = require("ui/widget/linewidget") local OverlapGroup = require("ui/widget/overlapgroup") local NumberPickerWidget = require("ui/widget/numberpickerwidget") local Size = require("ui/size") +local TextBoxWidget = require("ui/widget/textboxwidget") local TextWidget = require("ui/widget/textwidget") local UIManager = require("ui/uimanager") local VerticalGroup = require("ui/widget/verticalgroup") @@ -22,6 +23,7 @@ local Screen = Device.screen local SpinWidget = InputContainer:new{ title_face = Font:getFace("x_smalltfont"), + text = nil, width = Screen:getWidth() * 0.95, height = Screen:getHeight(), value = 1, @@ -68,6 +70,7 @@ function SpinWidget:update() value_max = self.value_max, value_step = self.value_step, value_hold_step = self.value_hold_step, + precision = self.precision, } local value_group = HorizontalGroup:new{ align = "center", @@ -127,30 +130,43 @@ function SpinWidget:update() show_parent = self, } + local vgroup = VerticalGroup:new{ + align = "left", + value_bar, + value_line, + } + if self.text then + table.insert(vgroup, FrameContainer:new{ + padding = Size.padding.default, + margin = Size.margin.small, + bordersize = 0, + TextBoxWidget:new{ + text = self.text, + face = Font:getFace("x_smallinfofont"), + width = self.width * 0.9, + } + }) + end + table.insert(vgroup, CenterContainer:new{ + dimen = Geom:new{ + w = self.width, + h = value_group:getSize().h + self.screen_height * 0.1, + }, + value_group + }) + table.insert(vgroup, CenterContainer:new{ + dimen = Geom:new{ + w = self.width, + h = ok_cancel_buttons:getSize().h, + }, + ok_cancel_buttons + }) self.spin_frame = FrameContainer:new{ radius = Size.radius.window, padding = 0, margin = 0, background = Blitbuffer.COLOR_WHITE, - VerticalGroup:new{ - align = "left", - value_bar, - value_line, - CenterContainer:new{ - dimen = Geom:new{ - w = self.width, - h = value_group:getSize().h + self.screen_height * 0.1, - }, - value_group - }, - CenterContainer:new{ - dimen = Geom:new{ - w = self.width, - h = ok_cancel_buttons:getSize().h, - }, - ok_cancel_buttons - } - } + vgroup, } self[1] = WidgetContainer:new{ align = "center",