2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local ButtonTable = require("ui/widget/buttontable")
|
2013-10-18 20:38:07 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2013-12-26 14:40:40 +00:00
|
|
|
local CloseButton = require("ui/widget/closebutton")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2014-08-17 16:32:09 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local Font = require("ui/font")
|
2017-04-29 08:38:09 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
2020-12-22 17:45:34 +00:00
|
|
|
local IconButton = require("ui/widget/iconbutton")
|
2017-04-29 08:38:09 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
2020-12-22 17:45:34 +00:00
|
|
|
local Math = require("optmath")
|
2018-01-29 20:27:24 +00:00
|
|
|
local MovableContainer = require("ui/widget/container/movablecontainer")
|
2017-04-29 08:38:09 +00:00
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
2018-01-07 19:24:15 +00:00
|
|
|
local ScrollHtmlWidget = require("ui/widget/scrollhtmlwidget")
|
2017-04-29 08:38:09 +00:00
|
|
|
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-04-29 08:38:09 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
The great Input/GestureDetector/TimeVal spring cleanup (a.k.a., a saner main loop) (#7415)
* ReaderDictionary: Port delay computations to TimeVal
* ReaderHighlight: Port delay computations to TimeVal
* ReaderView: Port delay computations to TimeVal
* Android: Reset gesture detection state on APP_CMD_TERM_WINDOW.
This prevents potentially being stuck in bogus gesture states when switching apps.
* GestureDetector:
* Port delay computations to TimeVal
* Fixed delay computations to handle time warps (large and negative deltas).
* Simplified timed callback handling to invalidate timers much earlier, preventing accumulating useless timers that no longer have any chance of ever detecting a gesture.
* Fixed state clearing to handle the actual effective slots, instead of hard-coding slot 0 & slot 1.
* Simplified timed callback handling in general, and added support for a timerfd backend for better performance and accuracy.
* The improved timed callback handling allows us to detect and honor (as much as possible) the three possible clock sources usable by Linux evdev events.
The only case where synthetic timestamps are used (and that only to handle timed callbacks) is limited to non-timerfd platforms where input events use
a clock source that is *NOT* MONOTONIC.
AFAICT, that's pretty much... PocketBook, and that's it?
* Input:
* Use the <linux/input.h> FFI module instead of re-declaring every constant
* Fixed (verbose) debug logging of input events to actually translate said constants properly.
* Completely reset gesture detection state on suspend. This should prevent bogus gesture detection on resume.
* Refactored the waitEvent loop to make it easier to comprehend (hopefully) and much more efficient.
Of specific note, it no longer does a crazy select spam every 100µs, instead computing and relying on sane timeouts,
as afforded by switching the UI event/input loop to the MONOTONIC time base, and the refactored timed callbacks in GestureDetector.
* reMarkable: Stopped enforcing synthetic timestamps on input events, as it should no longer be necessary.
* TimeVal:
* Refactored and simplified, especially as far as metamethods are concerned (based on <bsd/sys/time.h>).
* Added a host of new methods to query the various POSIX clock sources, and made :now default to MONOTONIC.
* Removed the debug guard in __sub, as time going backwards can be a perfectly normal occurrence.
* New methods:
* Clock sources: :realtime, :monotonic, :monotonic_coarse, :realtime_coarse, :boottime
* Utility: :tonumber, :tousecs, :tomsecs, :fromnumber, :isPositive, :isZero
* UIManager:
* Ported event loop & scheduling to TimeVal, and switched to the MONOTONIC time base.
This ensures reliable and consistent scheduling, as time is ensured never to go backwards.
* Added a :getTime() method, that returns a cached TimeVal:now(), updated at the top of every UI frame.
It's used throughout the codebase to cadge a syscall in circumstances where we are guaranteed that a syscall would return a mostly identical value,
because very few time has passed.
The only code left that does live syscalls does it because it's actually necessary for accuracy,
and the only code left that does that in a REALTIME time base is code that *actually* deals with calendar time (e.g., Statistics).
* DictQuickLookup: Port delay computations to TimeVal
* FootNoteWidget: Port delay computations to TimeVal
* HTMLBoxWidget: Port delay computations to TimeVal
* Notification: Port delay computations to TimeVal
* TextBoxWidget: Port delay computations to TimeVal
* AutoSuspend: Port to TimeVal
* AutoTurn:
* Fix it so that settings are actually honored.
* Port to TimeVal
* BackgroundRunner: Port to TimeVal
* Calibre: Port benchmarking code to TimeVal
* BookInfoManager: Removed unnecessary yield in the metadata extraction subprocess now that subprocesses get scheduled properly.
* All in all, these changes reduced the CPU cost of a single tap by a factor of ten (!), and got rid of an insane amount of weird poll/wakeup cycles that must have been hell on CPU schedulers and batteries..
2021-03-30 00:57:59 +00:00
|
|
|
local TimeVal = require("ui/timeval")
|
2017-04-29 08:38:09 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2020-12-22 17:45:34 +00:00
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2017-04-29 08:38:09 +00:00
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2017-04-29 08:38:09 +00:00
|
|
|
local util = require("util")
|
2013-10-22 15:11:31 +00:00
|
|
|
local _ = require("gettext")
|
2019-08-24 07:25:38 +00:00
|
|
|
local C_ = _.pgettext
|
2021-01-09 20:59:31 +00:00
|
|
|
local Input = Device.input
|
2017-04-29 08:38:09 +00:00
|
|
|
local Screen = Device.screen
|
2016-12-06 21:15:52 +00:00
|
|
|
local T = require("ffi/util").template
|
2013-04-24 14:57:03 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
Display quick lookup word definition
|
|
|
|
]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local DictQuickLookup = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
results = nil,
|
|
|
|
lookupword = nil,
|
|
|
|
dictionary = nil,
|
|
|
|
definition = nil,
|
2016-12-06 21:15:52 +00:00
|
|
|
displayword = nil,
|
2018-01-16 11:32:49 +00:00
|
|
|
images = nil,
|
2016-12-06 21:15:52 +00:00
|
|
|
is_wiki = false,
|
2020-12-22 17:45:34 +00:00
|
|
|
is_wiki_fullpage = false,
|
2018-01-07 19:24:15 +00:00
|
|
|
is_html = false,
|
2014-03-13 13:52:43 +00:00
|
|
|
dict_index = 1,
|
|
|
|
width = nil,
|
|
|
|
height = nil,
|
2014-08-20 06:41:45 +00:00
|
|
|
-- box of highlighted word, quick lookup window tries to not hide the word
|
|
|
|
word_box = nil,
|
2014-05-01 10:37:12 +00:00
|
|
|
|
2017-03-24 07:20:37 +00:00
|
|
|
-- refresh_callback will be called before we trigger full refresh in onSwipe
|
|
|
|
refresh_callback = nil,
|
2018-01-15 22:51:43 +00:00
|
|
|
html_dictionary_link_tapped_callback = nil,
|
2013-04-24 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 21:17:35 +00:00
|
|
|
local highlight_strings = {
|
|
|
|
highlight =_("Highlight"),
|
|
|
|
unhighlight = _("Unhighlight"),
|
|
|
|
}
|
|
|
|
|
2021-03-21 12:57:18 +00:00
|
|
|
function DictQuickLookup:canSearch()
|
|
|
|
if self:isDocless() then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.is_wiki then
|
|
|
|
-- In the Wiki variant of this widget, the Search button is coopted to cycle between enabled languages.
|
|
|
|
if #self.wiki_languages > 1 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- This is to prevent an ineffective button when we're launched from the Reader's menu.
|
|
|
|
if self.ui.highlight.selected_text then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2013-04-24 14:57:03 +00:00
|
|
|
function DictQuickLookup:init()
|
2020-12-22 17:45:34 +00:00
|
|
|
self.dict_font_size = G_reader_settings:readSetting("dict_font_size") or 20
|
|
|
|
self.content_face = Font:getFace("cfont", self.dict_font_size)
|
|
|
|
local font_size_alt = self.dict_font_size - 4
|
2019-11-27 22:59:08 +00:00
|
|
|
if font_size_alt < 8 then
|
|
|
|
font_size_alt = 8
|
|
|
|
end
|
|
|
|
self.image_alt_face = Font:getFace("cfont", font_size_alt)
|
2014-06-10 07:57:10 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events = {
|
2021-01-09 20:59:31 +00:00
|
|
|
ReadPrevResult = {{Input.group.PgBack}, doc = "read prev result"},
|
|
|
|
ReadNextResult = {{Input.group.PgFwd}, doc = "read next result"},
|
2014-06-10 07:57:10 +00:00
|
|
|
Close = { {"Back"}, doc = "close quick lookup" }
|
|
|
|
}
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
if Device:isTouchDevice() then
|
2018-03-05 20:27:55 +00:00
|
|
|
local range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ges_events = {
|
2020-12-22 17:45:34 +00:00
|
|
|
Tap = {
|
2014-03-13 13:52:43 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Swipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
-- This was for selection of a single word with simple hold
|
|
|
|
-- HoldWord = {
|
|
|
|
-- GestureRange:new{
|
|
|
|
-- ges = "hold",
|
|
|
|
-- range = function()
|
|
|
|
-- return self.region
|
|
|
|
-- end,
|
|
|
|
-- },
|
|
|
|
-- -- callback function when HoldWord is handled as args
|
|
|
|
-- args = function(word)
|
|
|
|
-- self.ui:handleEvent(
|
|
|
|
-- -- don't pass self.highlight to subsequent lookup, we want
|
|
|
|
-- -- the first to be the only one to unhighlight selection
|
|
|
|
-- -- when closed
|
|
|
|
-- Event:new("LookupWord", word, self.word_box))
|
|
|
|
-- end
|
|
|
|
-- },
|
|
|
|
-- Allow selection of one or more words (see textboxwidget.lua) :
|
|
|
|
HoldStartText = {
|
2015-10-18 12:46:22 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2015-10-18 12:46:22 +00:00
|
|
|
},
|
2018-03-07 14:59:59 +00:00
|
|
|
},
|
|
|
|
HoldPanText = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = range,
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
},
|
|
|
|
HoldReleaseText = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold_release",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2016-12-06 21:15:52 +00:00
|
|
|
},
|
|
|
|
-- callback function when HoldReleaseText is handled as args
|
|
|
|
args = function(text, hold_duration)
|
|
|
|
local lookup_target
|
The great Input/GestureDetector/TimeVal spring cleanup (a.k.a., a saner main loop) (#7415)
* ReaderDictionary: Port delay computations to TimeVal
* ReaderHighlight: Port delay computations to TimeVal
* ReaderView: Port delay computations to TimeVal
* Android: Reset gesture detection state on APP_CMD_TERM_WINDOW.
This prevents potentially being stuck in bogus gesture states when switching apps.
* GestureDetector:
* Port delay computations to TimeVal
* Fixed delay computations to handle time warps (large and negative deltas).
* Simplified timed callback handling to invalidate timers much earlier, preventing accumulating useless timers that no longer have any chance of ever detecting a gesture.
* Fixed state clearing to handle the actual effective slots, instead of hard-coding slot 0 & slot 1.
* Simplified timed callback handling in general, and added support for a timerfd backend for better performance and accuracy.
* The improved timed callback handling allows us to detect and honor (as much as possible) the three possible clock sources usable by Linux evdev events.
The only case where synthetic timestamps are used (and that only to handle timed callbacks) is limited to non-timerfd platforms where input events use
a clock source that is *NOT* MONOTONIC.
AFAICT, that's pretty much... PocketBook, and that's it?
* Input:
* Use the <linux/input.h> FFI module instead of re-declaring every constant
* Fixed (verbose) debug logging of input events to actually translate said constants properly.
* Completely reset gesture detection state on suspend. This should prevent bogus gesture detection on resume.
* Refactored the waitEvent loop to make it easier to comprehend (hopefully) and much more efficient.
Of specific note, it no longer does a crazy select spam every 100µs, instead computing and relying on sane timeouts,
as afforded by switching the UI event/input loop to the MONOTONIC time base, and the refactored timed callbacks in GestureDetector.
* reMarkable: Stopped enforcing synthetic timestamps on input events, as it should no longer be necessary.
* TimeVal:
* Refactored and simplified, especially as far as metamethods are concerned (based on <bsd/sys/time.h>).
* Added a host of new methods to query the various POSIX clock sources, and made :now default to MONOTONIC.
* Removed the debug guard in __sub, as time going backwards can be a perfectly normal occurrence.
* New methods:
* Clock sources: :realtime, :monotonic, :monotonic_coarse, :realtime_coarse, :boottime
* Utility: :tonumber, :tousecs, :tomsecs, :fromnumber, :isPositive, :isZero
* UIManager:
* Ported event loop & scheduling to TimeVal, and switched to the MONOTONIC time base.
This ensures reliable and consistent scheduling, as time is ensured never to go backwards.
* Added a :getTime() method, that returns a cached TimeVal:now(), updated at the top of every UI frame.
It's used throughout the codebase to cadge a syscall in circumstances where we are guaranteed that a syscall would return a mostly identical value,
because very few time has passed.
The only code left that does live syscalls does it because it's actually necessary for accuracy,
and the only code left that does that in a REALTIME time base is code that *actually* deals with calendar time (e.g., Statistics).
* DictQuickLookup: Port delay computations to TimeVal
* FootNoteWidget: Port delay computations to TimeVal
* HTMLBoxWidget: Port delay computations to TimeVal
* Notification: Port delay computations to TimeVal
* TextBoxWidget: Port delay computations to TimeVal
* AutoSuspend: Port to TimeVal
* AutoTurn:
* Fix it so that settings are actually honored.
* Port to TimeVal
* BackgroundRunner: Port to TimeVal
* Calibre: Port benchmarking code to TimeVal
* BookInfoManager: Removed unnecessary yield in the metadata extraction subprocess now that subprocesses get scheduled properly.
* All in all, these changes reduced the CPU cost of a single tap by a factor of ten (!), and got rid of an insane amount of weird poll/wakeup cycles that must have been hell on CPU schedulers and batteries..
2021-03-30 00:57:59 +00:00
|
|
|
if hold_duration < TimeVal:new{ sec = 3 } then
|
2016-12-06 21:15:52 +00:00
|
|
|
-- do this lookup in the same domain (dict/wikipedia)
|
|
|
|
lookup_target = self.is_wiki and "LookupWikipedia" or "LookupWord"
|
|
|
|
else
|
|
|
|
-- but allow switching domain with a long hold
|
|
|
|
lookup_target = self.is_wiki and "LookupWord" or "LookupWikipedia"
|
|
|
|
end
|
2017-01-01 09:34:21 +00:00
|
|
|
if lookup_target == "LookupWikipedia" then
|
|
|
|
self:resyncWikiLanguages()
|
|
|
|
end
|
2016-06-05 07:08:23 +00:00
|
|
|
self.ui:handleEvent(
|
2016-12-06 21:15:52 +00:00
|
|
|
-- don't pass self.highlight to subsequent lookup, we want
|
|
|
|
-- the first to be the only one to unhighlight selection
|
|
|
|
-- when closed
|
|
|
|
Event:new(lookup_target, text)
|
|
|
|
)
|
2015-10-18 12:46:22 +00:00
|
|
|
end
|
|
|
|
},
|
2018-03-07 14:59:59 +00:00
|
|
|
-- These will be forwarded to MovableContainer after some checks
|
2018-03-05 20:27:55 +00:00
|
|
|
ForwardingTouch = { GestureRange:new{ ges = "touch", range = range, }, },
|
|
|
|
ForwardingPan = { GestureRange:new{ ges = "pan", range = range, }, },
|
|
|
|
ForwardingPanRelease = { GestureRange:new{ ges = "pan_release", range = range, }, },
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2020-12-22 17:45:34 +00:00
|
|
|
|
|
|
|
-- We no longer support setting a default dict with Tap on title.
|
|
|
|
-- self:changeToDefaultDict()
|
|
|
|
-- Now, dictionaries can be ordered (although not yet per-book), so trust the order set
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self:changeDictionary(1, true) -- don't call update
|
2020-12-22 17:45:34 +00:00
|
|
|
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
-- And here comes the initial widget layout...
|
2020-12-22 17:45:34 +00:00
|
|
|
if self.is_wiki then
|
|
|
|
-- Keep a copy of self.wiki_languages for use
|
|
|
|
-- by DictQuickLookup:resyncWikiLanguages()
|
|
|
|
self.wiki_languages_copy = self.wiki_languages and {unpack(self.wiki_languages)} or nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Bigger window if fullpage Wikipedia article being shown,
|
|
|
|
-- or when large windows for dict requested
|
|
|
|
local is_large_window = self.is_wiki_fullpage or G_reader_settings:isTrue("dict_largewindow")
|
|
|
|
if is_large_window then
|
|
|
|
self.width = Screen:getWidth() - 2*Size.margin.default
|
2016-12-06 21:15:52 +00:00
|
|
|
else
|
2020-12-22 17:45:34 +00:00
|
|
|
self.width = Screen:getWidth() - Screen:scaleBySize(80)
|
2014-08-20 06:41:45 +00:00
|
|
|
end
|
2020-12-22 17:45:34 +00:00
|
|
|
local frame_bordersize = Size.border.window
|
|
|
|
local inner_width = self.width - 2*frame_bordersize
|
|
|
|
-- Height will be computed below, after we build top an bottom
|
|
|
|
-- components, when we know how much height they are taking.
|
|
|
|
|
|
|
|
-- Dictionary title
|
|
|
|
-- (a bit convoluted with margin & padding but no border, but let's
|
|
|
|
-- do as other widgets to get the same look)
|
|
|
|
local title_margin = Size.margin.title
|
|
|
|
local title_padding = Size.padding.default
|
|
|
|
local title_width = inner_width - 2*title_padding -2*title_margin
|
|
|
|
local close_button = CloseButton:new{ window = self, padding_top = title_margin, }
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.dict_title_text = TextWidget:new{
|
2021-01-06 20:49:23 +00:00
|
|
|
text = self.displaydictname,
|
2020-12-22 17:45:34 +00:00
|
|
|
face = Font:getFace("x_smalltfont"),
|
2016-12-06 21:15:52 +00:00
|
|
|
bold = true,
|
2020-12-22 17:45:34 +00:00
|
|
|
max_width = title_width - close_button:getSize().w + close_button.padding_left
|
|
|
|
-- Allow text to eat on the CloseButton padding_left (which
|
|
|
|
-- is quite large to ensure a bigger tap area)
|
2016-12-06 21:15:52 +00:00
|
|
|
}
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
local dict_title_widget = self.dict_title_text
|
2016-12-06 21:15:52 +00:00
|
|
|
if self.is_wiki then
|
2020-12-22 17:45:34 +00:00
|
|
|
-- Visual hint: title left aligned for dict, but centered for Wikipedia
|
2019-12-06 21:55:26 +00:00
|
|
|
dict_title_widget = CenterContainer:new{
|
2020-12-22 17:45:34 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = title_width,
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
h = self.dict_title_text:getSize().h,
|
2020-12-22 17:45:34 +00:00
|
|
|
},
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.dict_title_text,
|
2016-12-06 21:15:52 +00:00
|
|
|
}
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_title = FrameContainer:new{
|
2020-12-22 17:45:34 +00:00
|
|
|
margin = title_margin,
|
2014-03-13 13:52:43 +00:00
|
|
|
bordersize = 0,
|
2020-12-22 17:45:34 +00:00
|
|
|
padding = title_padding,
|
2019-12-06 21:55:26 +00:00
|
|
|
dict_title_widget,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2020-12-22 17:45:34 +00:00
|
|
|
local title_bar = OverlapGroup:new{
|
|
|
|
dimen = {
|
|
|
|
w = inner_width,
|
|
|
|
h = self.dict_title:getSize().h
|
|
|
|
},
|
|
|
|
self.dict_title,
|
|
|
|
close_button,
|
|
|
|
}
|
|
|
|
local title_sep = LineWidget:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = inner_width,
|
|
|
|
h = Size.line.thick,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2018-01-07 19:24:15 +00:00
|
|
|
|
2020-12-22 17:45:34 +00:00
|
|
|
-- This padding and the resulting width apply to the content
|
|
|
|
-- below the title: lookup word and definition
|
|
|
|
local content_padding_h = Size.padding.large
|
|
|
|
local content_padding_v = Size.padding.large -- added via VerticalSpan
|
2021-01-31 01:51:40 +00:00
|
|
|
self.content_width = inner_width - 2*content_padding_h
|
2018-01-07 19:24:15 +00:00
|
|
|
|
2020-12-22 17:45:34 +00:00
|
|
|
-- Spans between components
|
|
|
|
local top_to_word_span = VerticalSpan:new{ width = content_padding_v }
|
|
|
|
local word_to_definition_span = VerticalSpan:new{ width = content_padding_v }
|
|
|
|
local definition_to_bottom_span = VerticalSpan:new{ width = content_padding_v }
|
|
|
|
|
|
|
|
-- Lookup word
|
|
|
|
local word_font_face = "tfont"
|
|
|
|
-- Ensure this word doesn't get smaller than its definition
|
|
|
|
local word_font_size = math.max(22, self.dict_font_size)
|
|
|
|
-- Get the line height of the normal font size, as a base for sizing this component
|
|
|
|
if not self.word_line_height then
|
|
|
|
local test_widget = TextWidget:new{
|
|
|
|
text = "z",
|
|
|
|
face = Font:getFace(word_font_face, word_font_size),
|
2018-01-07 19:24:15 +00:00
|
|
|
}
|
2020-12-22 17:45:34 +00:00
|
|
|
self.word_line_height = test_widget:getSize().h
|
|
|
|
test_widget:free()
|
2018-01-07 19:24:15 +00:00
|
|
|
end
|
2020-12-22 17:45:34 +00:00
|
|
|
if self.is_wiki then
|
|
|
|
-- Wikipedia has longer titles, so use a smaller font,
|
|
|
|
word_font_size = math.max(18, self.dict_font_size)
|
|
|
|
end
|
|
|
|
local icon_size = Screen:scaleBySize(32)
|
|
|
|
local lookup_height = math.max(self.word_line_height, icon_size)
|
|
|
|
-- Edit button
|
|
|
|
local lookup_edit_button = IconButton:new{
|
|
|
|
icon = "edit",
|
|
|
|
width = icon_size,
|
|
|
|
height = icon_size,
|
|
|
|
padding = 0,
|
|
|
|
padding_left = Size.padding.small,
|
|
|
|
callback = function()
|
|
|
|
-- allow adjusting the queried word
|
|
|
|
self:lookupInputWord(self.word)
|
|
|
|
end,
|
|
|
|
hold_callback = function()
|
|
|
|
-- allow adjusting the current result word
|
|
|
|
self:lookupInputWord(self.lookupword)
|
|
|
|
end,
|
|
|
|
overlap_align = "right",
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
show_parent = self,
|
2014-05-01 10:37:12 +00:00
|
|
|
}
|
2020-12-22 17:45:34 +00:00
|
|
|
local lookup_edit_button_w = lookup_edit_button:getSize().w
|
|
|
|
-- Nb of results (if set)
|
|
|
|
local lookup_word_nb
|
|
|
|
local lookup_word_nb_w = 0
|
|
|
|
if self.displaynb then
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.displaynb_text = TextWidget:new{
|
|
|
|
text = self.displaynb,
|
|
|
|
face = Font:getFace("cfont", word_font_size),
|
|
|
|
padding = 0, -- smaller height for better aligmnent with icon
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:45:34 +00:00
|
|
|
lookup_word_nb = FrameContainer:new{
|
|
|
|
margin = 0,
|
|
|
|
bordersize = 0,
|
|
|
|
padding = 0,
|
|
|
|
padding_left = Size.padding.small,
|
|
|
|
padding_right = lookup_edit_button_w + Size.padding.default,
|
|
|
|
overlap_align = "right",
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.displaynb_text,
|
2020-12-22 17:45:34 +00:00
|
|
|
}
|
|
|
|
lookup_word_nb_w = lookup_word_nb:getSize().w
|
|
|
|
end
|
|
|
|
-- Lookup word
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.lookup_word_text = TextWidget:new{
|
2020-12-22 17:45:34 +00:00
|
|
|
text = self.displayword,
|
|
|
|
face = Font:getFace(word_font_face, word_font_size),
|
|
|
|
bold = true,
|
2021-01-31 01:51:40 +00:00
|
|
|
max_width = self.content_width - math.max(lookup_edit_button_w, lookup_word_nb_w),
|
2020-12-22 17:45:34 +00:00
|
|
|
padding = 0, -- to be aligned with lookup_word_nb
|
|
|
|
}
|
|
|
|
-- Group these 3 widgets
|
|
|
|
local lookup_word = OverlapGroup:new{
|
|
|
|
dimen = {
|
2021-01-31 01:51:40 +00:00
|
|
|
w = self.content_width,
|
2020-12-22 17:45:34 +00:00
|
|
|
h = lookup_height,
|
|
|
|
},
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.lookup_word_text,
|
2020-12-22 17:45:34 +00:00
|
|
|
lookup_edit_button,
|
|
|
|
lookup_word_nb, -- last, as this might be nil
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Different sets of buttons whether fullpage or not
|
2016-12-06 21:15:52 +00:00
|
|
|
local buttons
|
2020-12-22 17:45:34 +00:00
|
|
|
if self.is_wiki_fullpage then
|
2017-01-21 18:23:13 +00:00
|
|
|
-- A save and a close button
|
2016-12-06 21:15:52 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
2017-01-21 18:23:13 +00:00
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "save",
|
2017-05-08 16:14:29 +00:00
|
|
|
text = _("Save as EPUB"),
|
2017-01-21 18:23:13 +00:00
|
|
|
callback = function()
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
-- if forced_lang was specified, it may not be in our wiki_languages,
|
|
|
|
-- but ReaderWikipedia will have put it in result.lang
|
|
|
|
local lang = self.lang or self.wiki_languages_copy[1]
|
|
|
|
-- Find a directory to save file into
|
2018-03-16 19:47:51 +00:00
|
|
|
local dir
|
|
|
|
if G_reader_settings:isTrue("wikipedia_save_in_book_dir") and not self:isDocless() then
|
|
|
|
local last_file = G_reader_settings:readSetting("lastfile")
|
|
|
|
if last_file then
|
|
|
|
dir = last_file:match("(.*)/")
|
|
|
|
end
|
|
|
|
end
|
2021-03-06 21:44:18 +00:00
|
|
|
if not dir then dir = G_reader_settings:readSetting("wikipedia_save_dir")
|
|
|
|
or G_reader_settings:readSetting("home_dir")
|
|
|
|
or require("apps/filemanager/filemanagerutil").getDefaultDir() end
|
2018-03-16 19:47:51 +00:00
|
|
|
if not dir or not util.pathExists(dir) then
|
2017-01-21 18:23:13 +00:00
|
|
|
UIManager:show(InfoMessage:new{
|
2021-03-28 11:35:56 +00:00
|
|
|
text = _("No folder to save article to could be found."),
|
2017-01-21 18:23:13 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
2020-09-18 10:40:43 +00:00
|
|
|
-- Just to be safe (none of the invalid chars, except ':' for uninteresting
|
|
|
|
-- Portal: or File: wikipedia pages, should be in lookupword)
|
|
|
|
local filename = self.lookupword .. "."..string.upper(lang)..".epub"
|
|
|
|
filename = util.getSafeFilename(filename, dir):gsub("_", " ")
|
2017-01-21 18:23:13 +00:00
|
|
|
local epub_path = dir .. "/" .. filename
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = T(_("Save as %1?"), BD.filename(filename)),
|
2017-01-21 18:23:13 +00:00
|
|
|
ok_callback = function()
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
local Wikipedia = require("ui/wikipedia")
|
|
|
|
Wikipedia:createEpubWithUI(epub_path, self.lookupword, lang, function(success)
|
|
|
|
if success then
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = T(_("Article saved to:\n%1\n\nWould you like to read the downloaded article now?"), BD.filepath(epub_path)),
|
2017-01-21 18:23:13 +00:00
|
|
|
ok_callback = function()
|
|
|
|
-- close all dict/wiki windows, without scheduleIn(highlight.clear())
|
|
|
|
self:onHoldClose(true)
|
|
|
|
-- close current ReaderUI in 1 sec, and create a new one
|
|
|
|
UIManager:scheduleIn(1.0, function()
|
2021-03-21 12:57:18 +00:00
|
|
|
if self.ui then
|
2017-10-24 13:22:10 +00:00
|
|
|
-- close Highlight menu if any still shown
|
2021-03-21 12:57:18 +00:00
|
|
|
if self.ui.highlight and self.ui.highlight.highlight_dialog then
|
|
|
|
self.ui.highlight:onClose()
|
2017-10-24 13:22:10 +00:00
|
|
|
end
|
2021-03-21 12:57:18 +00:00
|
|
|
self.ui:onClose()
|
2017-01-21 18:23:13 +00:00
|
|
|
end
|
2021-03-21 12:57:18 +00:00
|
|
|
self.ui:showReader(epub_path)
|
2017-01-21 18:23:13 +00:00
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
2021-01-09 20:59:27 +00:00
|
|
|
text = _("Saving Wikipedia article failed or interrupted."),
|
2017-01-21 18:23:13 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "close",
|
2017-05-08 16:14:29 +00:00
|
|
|
text = _("Close"),
|
2016-12-06 21:15:52 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:close(self)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
else
|
2019-12-06 21:55:39 +00:00
|
|
|
local prev_dict_text = "◁◁"
|
|
|
|
local next_dict_text = "▷▷"
|
|
|
|
if BD.mirroredUILayout() then
|
|
|
|
prev_dict_text, next_dict_text = next_dict_text, prev_dict_text
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
buttons = {
|
2014-05-01 10:37:12 +00:00
|
|
|
{
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "prev_dict",
|
2019-12-06 21:55:39 +00:00
|
|
|
text = prev_dict_text,
|
Assorted fixes after #7118 (#7161)
* I'd failed to notice that ButtonTable *also* instantiates seven billion Buttons on each update. Unfortunately, that one is way trickier to fix properly, so, work around its behavior in Button. (This fixes multiple issues with stuff using ButtonTable, which is basically anything with a persistent set of buttons. A good and easy test-case is the dictionary popup, e.g., the Highlight button changes text, and the next/prev dic buttons change state. All that, and more, was broken ;p).
* Handle corner-cases related to VirtualKeyboard (e.g., Terminal & Text Editor), which screwed with both TouchMenu & Button heuristics because it's weird.
* Flag a the dictionary switch buttons as vsync
(They trigger a partial repaint of the dictionary content).
* Flag the ReaderSearch buttons as vsync
They very obviously trigger a partial repaint, much like SkimTo ;p.
2021-01-18 15:51:25 +00:00
|
|
|
vsync = true,
|
2014-03-13 13:52:43 +00:00
|
|
|
enabled = self:isPrevDictAvaiable(),
|
|
|
|
callback = function()
|
|
|
|
self:changeToPrevDict()
|
|
|
|
end,
|
2021-01-01 13:34:53 +00:00
|
|
|
hold_callback = function()
|
|
|
|
self:changeToFirstDict()
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2014-08-11 13:49:42 +00:00
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "highlight",
|
2015-03-12 10:50:57 +00:00
|
|
|
text = self:getHighlightText(),
|
2021-03-21 12:57:18 +00:00
|
|
|
enabled = not self:isDocless() and self.highlight ~= nil,
|
2014-08-11 13:49:42 +00:00
|
|
|
callback = function()
|
2017-09-01 21:17:35 +00:00
|
|
|
if self:getHighlightText() == highlight_strings.highlight then
|
2017-07-28 20:39:54 +00:00
|
|
|
self.ui:handleEvent(Event:new("Highlight"))
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("Unhighlight"))
|
|
|
|
end
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
-- Just update, repaint and refresh *this* button
|
|
|
|
local this = self.button_table:getButtonById("highlight")
|
|
|
|
if not this then return end
|
|
|
|
this:enableDisable(self.highlight ~= nil)
|
|
|
|
this:setText(self:getHighlightText(), this.width)
|
|
|
|
this:refresh()
|
2014-08-11 13:49:42 +00:00
|
|
|
end,
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "next_dict",
|
2019-12-06 21:55:39 +00:00
|
|
|
text = next_dict_text,
|
Assorted fixes after #7118 (#7161)
* I'd failed to notice that ButtonTable *also* instantiates seven billion Buttons on each update. Unfortunately, that one is way trickier to fix properly, so, work around its behavior in Button. (This fixes multiple issues with stuff using ButtonTable, which is basically anything with a persistent set of buttons. A good and easy test-case is the dictionary popup, e.g., the Highlight button changes text, and the next/prev dic buttons change state. All that, and more, was broken ;p).
* Handle corner-cases related to VirtualKeyboard (e.g., Terminal & Text Editor), which screwed with both TouchMenu & Button heuristics because it's weird.
* Flag a the dictionary switch buttons as vsync
(They trigger a partial repaint of the dictionary content).
* Flag the ReaderSearch buttons as vsync
They very obviously trigger a partial repaint, much like SkimTo ;p.
2021-01-18 15:51:25 +00:00
|
|
|
vsync = true,
|
2014-03-13 13:52:43 +00:00
|
|
|
enabled = self:isNextDictAvaiable(),
|
|
|
|
callback = function()
|
|
|
|
self:changeToNextDict()
|
|
|
|
end,
|
2021-01-01 13:34:53 +00:00
|
|
|
hold_callback = function()
|
|
|
|
self:changeToLastDict()
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "wikipedia",
|
2016-12-06 21:15:52 +00:00
|
|
|
-- if dictionary result, do the same search on wikipedia
|
|
|
|
-- if already wiki, get the full page for the current result
|
2019-08-24 07:25:38 +00:00
|
|
|
text_func = function()
|
|
|
|
if self.is_wiki then
|
|
|
|
-- @translators Full Wikipedia article.
|
|
|
|
return C_("Button", "Wikipedia full")
|
|
|
|
else
|
|
|
|
return _("Wikipedia")
|
|
|
|
end
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2014-08-20 06:41:45 +00:00
|
|
|
UIManager:scheduleIn(0.1, function()
|
2016-12-06 21:15:52 +00:00
|
|
|
self:lookupWikipedia(self.is_wiki) -- will get_fullpage if is_wiki
|
2014-08-20 06:41:45 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
2020-12-22 17:45:34 +00:00
|
|
|
-- Rotate thru available wikipedia languages, or Search in book if dict window
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "search",
|
2016-12-06 21:15:52 +00:00
|
|
|
-- if more than one language, enable it and display "current lang > next lang"
|
|
|
|
-- otherwise, just display current lang
|
2019-12-06 21:55:39 +00:00
|
|
|
text = self.is_wiki
|
|
|
|
and ( #self.wiki_languages > 1 and BD.wrap(self.wiki_languages[1]).." > "..BD.wrap(self.wiki_languages[2])
|
|
|
|
or self.wiki_languages[1] ) -- (this " > " will be auro-mirrored by bidi)
|
2020-12-22 17:45:34 +00:00
|
|
|
or _("Search"),
|
2021-03-21 12:57:18 +00:00
|
|
|
enabled = self:canSearch(),
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2017-09-09 16:30:00 +00:00
|
|
|
if self.is_wiki then
|
|
|
|
self:resyncWikiLanguages(true) -- rotate & resync them
|
|
|
|
UIManager:close(self)
|
|
|
|
self:lookupWikipedia()
|
|
|
|
else
|
2020-12-22 17:45:34 +00:00
|
|
|
self.ui:handleEvent(Event:new("HighlightSearch"))
|
|
|
|
UIManager:close(self)
|
2017-09-09 16:30:00 +00:00
|
|
|
end
|
2014-08-11 13:49:42 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "close",
|
2020-12-22 17:45:34 +00:00
|
|
|
text = _("Close"),
|
2014-08-11 13:49:42 +00:00
|
|
|
callback = function()
|
2020-12-22 17:45:34 +00:00
|
|
|
-- UIManager:close(self)
|
|
|
|
self:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
}
|
2020-12-22 17:45:34 +00:00
|
|
|
if not self.is_wiki and self.selected_link ~= nil then
|
|
|
|
-- If highlighting some word part of a link (which should be rare),
|
|
|
|
-- add a new first row with a single button to follow this link.
|
|
|
|
table.insert(buttons, 1, {
|
|
|
|
{
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
id = "link",
|
2020-12-22 17:45:34 +00:00
|
|
|
text = _("Follow Link"),
|
|
|
|
callback = function()
|
|
|
|
local link = self.selected_link.link or self.selected_link
|
|
|
|
self.ui.link:onGotoLink(link)
|
|
|
|
self:onClose()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
2016-12-06 21:15:52 +00:00
|
|
|
end
|
|
|
|
|
2020-12-22 17:45:34 +00:00
|
|
|
-- Bottom buttons get a bit less padding so their line separators
|
|
|
|
-- reach out from the content to the borders a bit more
|
|
|
|
local buttons_padding = Size.padding.default
|
|
|
|
local buttons_width = inner_width - 2*buttons_padding
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.button_table = ButtonTable:new{
|
2020-12-22 17:45:34 +00:00
|
|
|
width = buttons_width,
|
2016-12-06 21:15:52 +00:00
|
|
|
button_font_face = "cfont",
|
|
|
|
button_font_size = 20,
|
|
|
|
buttons = buttons,
|
2014-03-13 13:52:43 +00:00
|
|
|
zero_sep = true,
|
2014-05-01 10:37:12 +00:00
|
|
|
show_parent = self,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2020-12-22 17:45:34 +00:00
|
|
|
|
|
|
|
-- Margin from screen edges
|
|
|
|
local margin_top = Size.margin.default
|
|
|
|
local margin_bottom = Size.margin.default
|
|
|
|
if self.ui and self.ui.view and self.ui.view.footer_visible then
|
|
|
|
-- We want to let the footer visible (as it can show time, battery level
|
|
|
|
-- and wifi state, which might be useful when spending time reading
|
|
|
|
-- definitions or wikipedia articles)
|
|
|
|
margin_bottom = margin_bottom + self.ui.view.footer:getHeight()
|
|
|
|
end
|
|
|
|
local avail_height = Screen:getHeight() - margin_top - margin_bottom
|
|
|
|
-- Region in which the window will be aligned center/top/bottom:
|
|
|
|
self.region = Geom:new{
|
|
|
|
x = 0,
|
|
|
|
y = margin_top,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = avail_height,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2020-12-22 17:45:34 +00:00
|
|
|
self.align = "center"
|
2014-05-01 10:37:12 +00:00
|
|
|
|
2020-12-22 17:45:34 +00:00
|
|
|
local others_height = frame_bordersize * 2 -- DictQuickLookup border
|
|
|
|
+ title_bar:getSize().h
|
|
|
|
+ title_sep:getSize().h
|
|
|
|
+ top_to_word_span:getSize().h
|
|
|
|
+ lookup_word:getSize().h
|
|
|
|
+ word_to_definition_span:getSize().h
|
|
|
|
+ definition_to_bottom_span:getSize().h
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
+ self.button_table:getSize().h
|
2020-12-22 17:45:34 +00:00
|
|
|
|
|
|
|
-- To properly adjust the definition to the height of text, we need
|
|
|
|
-- the line height a ScrollTextWidget will use for the current font
|
|
|
|
-- size (we'll then use this perfect height for ScrollTextWidget,
|
|
|
|
-- but also for ScrollHtmlWidget, where it doesn't matter).
|
|
|
|
if not self.definition_line_height then
|
|
|
|
local test_widget = ScrollTextWidget:new{
|
|
|
|
text = "z",
|
|
|
|
face = self.content_face,
|
2021-01-31 01:51:40 +00:00
|
|
|
width = self.content_width,
|
2020-12-22 17:45:34 +00:00
|
|
|
height = self.definition_height,
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
for_measurement_only = true, -- flag it as a dummy, so it won't trigger any bogus repaint/refresh...
|
2020-12-22 17:45:34 +00:00
|
|
|
}
|
|
|
|
self.definition_line_height = test_widget:getLineHeight()
|
|
|
|
test_widget:free()
|
|
|
|
end
|
|
|
|
|
|
|
|
if is_large_window then
|
|
|
|
-- Available height for definition + components
|
|
|
|
self.height = avail_height
|
|
|
|
self.definition_height = self.height - others_height
|
|
|
|
local nb_lines = math.floor(self.definition_height / self.definition_line_height)
|
|
|
|
self.definition_height = nb_lines * self.definition_line_height
|
|
|
|
local pad = self.height - others_height - self.definition_height
|
|
|
|
-- put that unused height on the above span
|
|
|
|
word_to_definition_span.width = word_to_definition_span.width + pad
|
|
|
|
else
|
|
|
|
-- Definition height was previously computed as 0.5*0.7*screen_height, so keep
|
|
|
|
-- it that way. Components will add themselves to that.
|
|
|
|
self.definition_height = math.floor(avail_height * 0.5 * 0.7)
|
|
|
|
-- But we want it to fit to the lines that will show, to avoid
|
|
|
|
-- any extra padding
|
|
|
|
local nb_lines = Math.round(self.definition_height / self.definition_line_height)
|
|
|
|
self.definition_height = nb_lines * self.definition_line_height
|
|
|
|
self.height = self.definition_height + others_height
|
|
|
|
if self.word_box then
|
|
|
|
-- Try to not hide the highlighted word. We don't want to always
|
|
|
|
-- get near it if we can stay center, so that more context around
|
|
|
|
-- the word is still visible with the dict result.
|
|
|
|
-- But if we were to be drawn over the word, move a bit if possible.
|
|
|
|
local box = self.word_box
|
|
|
|
-- Don't stick to the box, ensure a minimal padding between box and window
|
|
|
|
local box_dict_padding = Size.padding.small
|
|
|
|
local word_box_top = box.y - box_dict_padding
|
|
|
|
local word_box_bottom = box.y + box.h + box_dict_padding
|
|
|
|
local half_visible_height = (avail_height - self.height) / 2
|
|
|
|
if word_box_bottom > half_visible_height and word_box_top <= half_visible_height + self.height then
|
|
|
|
-- word would be covered by our centered window
|
|
|
|
if word_box_bottom <= avail_height - self.height then
|
|
|
|
-- Window can be moved just below word
|
|
|
|
self.region.y = word_box_bottom
|
|
|
|
self.region.h = self.region.h - word_box_bottom
|
|
|
|
self.align = "top"
|
|
|
|
elseif word_box_top > self.height then
|
|
|
|
-- Window can be moved just above word
|
|
|
|
self.region.y = 0
|
|
|
|
self.region.h = word_box_top
|
|
|
|
self.align = "bottom"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-31 01:51:40 +00:00
|
|
|
-- Instantiate self.text_widget
|
|
|
|
self:_instantiateScrollWidget()
|
2020-12-22 17:45:34 +00:00
|
|
|
|
|
|
|
-- word definition
|
|
|
|
self.definition_widget = FrameContainer:new{
|
|
|
|
padding = 0,
|
|
|
|
padding_left = content_padding_h,
|
|
|
|
padding_right = content_padding_h,
|
|
|
|
margin = 0,
|
|
|
|
bordersize = 0,
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.text_widget,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2014-05-01 10:37:12 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
2020-12-22 17:45:34 +00:00
|
|
|
bordersize = frame_bordersize,
|
2014-03-13 13:52:43 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
title_bar,
|
2020-12-22 17:45:34 +00:00
|
|
|
title_sep,
|
|
|
|
top_to_word_span,
|
2014-03-13 13:52:43 +00:00
|
|
|
-- word
|
2020-12-22 17:45:34 +00:00
|
|
|
CenterContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
dimen = Geom:new{
|
2020-12-22 17:45:34 +00:00
|
|
|
w = inner_width,
|
2014-03-13 13:52:43 +00:00
|
|
|
h = lookup_word:getSize().h,
|
|
|
|
},
|
|
|
|
lookup_word,
|
|
|
|
},
|
2020-12-22 17:45:34 +00:00
|
|
|
word_to_definition_span,
|
2014-03-13 13:52:43 +00:00
|
|
|
-- definition
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
2020-12-22 17:45:34 +00:00
|
|
|
w = inner_width,
|
2018-01-29 20:27:24 +00:00
|
|
|
h = self.definition_widget:getSize().h,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2018-01-29 20:27:24 +00:00
|
|
|
self.definition_widget,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2020-12-22 17:45:34 +00:00
|
|
|
definition_to_bottom_span,
|
2014-03-13 13:52:43 +00:00
|
|
|
-- buttons
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
2020-12-22 17:45:34 +00:00
|
|
|
w = inner_width,
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
h = self.button_table:getSize().h,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.button_table,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-29 20:27:24 +00:00
|
|
|
|
|
|
|
self.movable = MovableContainer:new{
|
|
|
|
-- We'll handle these events ourselves, and call appropriate
|
|
|
|
-- MovableContainer's methods when we didn't process the event
|
2018-03-05 20:27:55 +00:00
|
|
|
ignore_events = {
|
|
|
|
-- These have effects over the definition widget, and may
|
|
|
|
-- or may not be processed by it
|
2018-03-07 14:59:59 +00:00
|
|
|
"swipe", "hold", "hold_release", "hold_pan",
|
2018-03-05 20:27:55 +00:00
|
|
|
-- These do not have direct effect over the definition widget,
|
|
|
|
-- but may happen while selecting text: we need to check
|
2018-03-07 14:59:59 +00:00
|
|
|
-- a few things before forwarding them
|
|
|
|
"touch", "pan", "pan_release",
|
2018-03-05 20:27:55 +00:00
|
|
|
},
|
2018-01-29 20:27:24 +00:00
|
|
|
self.dict_frame,
|
|
|
|
}
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
align = self.align,
|
2014-08-20 06:41:45 +00:00
|
|
|
dimen = self.region,
|
2018-01-29 20:27:24 +00:00
|
|
|
self.movable,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
UIManager:setDirty(self, function()
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
return "partial", self.dict_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Whether currently DictQuickLookup is working without a document.
|
|
|
|
function DictQuickLookup:isDocless()
|
|
|
|
return self.ui == nil or self.ui.highlight == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:getHtmlDictionaryCss()
|
|
|
|
-- Using Noto Sans because Nimbus doesn't contain the IPA symbols.
|
|
|
|
-- 'line-height: 1.3' to have it similar to textboxwidget,
|
|
|
|
-- and follow user's choice on justification
|
|
|
|
local css_justify = G_reader_settings:nilOrTrue("dict_justify") and "text-align: justify;" or ""
|
|
|
|
local css = [[
|
|
|
|
@page {
|
|
|
|
margin: 0;
|
|
|
|
font-family: 'Noto Sans';
|
|
|
|
}
|
|
|
|
|
|
|
|
body {
|
|
|
|
margin: 0;
|
|
|
|
line-height: 1.3;
|
|
|
|
]]..css_justify..[[
|
|
|
|
}
|
|
|
|
|
|
|
|
blockquote, dd {
|
|
|
|
margin: 0 1em;
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
-- MuPDF doesn't currently scale CSS pixels, so we have to use a font-size based measurement.
|
|
|
|
-- Unfortunately MuPDF doesn't properly support `rem` either, which it bases on a hard-coded
|
|
|
|
-- value of `16px`, so we have to go with `em` (or `%`).
|
|
|
|
--
|
|
|
|
-- These `em`-based margins can vary slightly, but it's the best available compromise.
|
|
|
|
--
|
|
|
|
-- We also keep left and right margin the same so it'll display as expected in RTL.
|
|
|
|
-- Because MuPDF doesn't currently support `margin-start`, this results in a slightly
|
|
|
|
-- unconventional but hopefully barely noticeable right margin for <dd>.
|
|
|
|
|
|
|
|
if self.css then
|
|
|
|
return css .. self.css
|
|
|
|
end
|
|
|
|
return css
|
|
|
|
end
|
|
|
|
|
2021-01-31 01:51:40 +00:00
|
|
|
-- Used in init & update to instantiate the Scroll*Widget that self.text_widget points to
|
|
|
|
function DictQuickLookup:_instantiateScrollWidget()
|
|
|
|
if self.is_html then
|
|
|
|
self.shw_widget = ScrollHtmlWidget:new{
|
|
|
|
html_body = self.definition,
|
|
|
|
css = self:getHtmlDictionaryCss(),
|
|
|
|
default_font_size = Screen:scaleBySize(self.dict_font_size),
|
|
|
|
width = self.content_width,
|
|
|
|
height = self.definition_height,
|
|
|
|
dialog = self,
|
|
|
|
html_link_tapped_callback = function(link)
|
|
|
|
self.html_dictionary_link_tapped_callback(self.dictionary, link)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
self.text_widget = self.shw_widget
|
|
|
|
else
|
|
|
|
self.stw_widget = ScrollTextWidget:new{
|
|
|
|
text = self.definition,
|
|
|
|
face = self.content_face,
|
|
|
|
width = self.content_width,
|
|
|
|
height = self.definition_height,
|
|
|
|
dialog = self,
|
|
|
|
justified = G_reader_settings:nilOrTrue("dict_justify"), -- allow for disabling justification
|
|
|
|
lang = self.lang and self.lang:lower(), -- only available on wikipedia results
|
|
|
|
para_direction_rtl = self.rtl_lang, -- only available on wikipedia results
|
|
|
|
auto_para_direction = not self.is_wiki, -- only for dict results (we don't know their lang)
|
|
|
|
image_alt_face = self.image_alt_face,
|
|
|
|
images = self.images,
|
|
|
|
}
|
|
|
|
self.text_widget = self.stw_widget
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
function DictQuickLookup:update()
|
|
|
|
-- self[1] is a WidgetContainer, its free method will call free on each of its child widget with a free method.
|
|
|
|
-- Here, that's the definitions' TextBoxWidget & HtmlBoxWidget,
|
|
|
|
-- to release their bb, MuPDF instance, and scheduled image_update_action.
|
|
|
|
self[1]:free()
|
|
|
|
|
|
|
|
-- Update TextWidgets
|
|
|
|
self.dict_title_text:setText(self.displaydictname)
|
|
|
|
if self.displaynb then
|
|
|
|
self.displaynb_text:setText(self.displaynb)
|
|
|
|
end
|
|
|
|
self.lookup_word_text:setText(self.displayword)
|
|
|
|
|
|
|
|
-- Update Buttons
|
|
|
|
if not self.is_wiki_fullpage then
|
|
|
|
local prev_dict_btn = self.button_table:getButtonById("prev_dict")
|
|
|
|
if prev_dict_btn then
|
|
|
|
prev_dict_btn:enableDisable(self:isPrevDictAvaiable())
|
|
|
|
end
|
|
|
|
local next_dict_btn = self.button_table:getButtonById("next_dict")
|
|
|
|
if next_dict_btn then
|
|
|
|
next_dict_btn:enableDisable(self:isNextDictAvaiable())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Update main text widgets
|
2021-01-31 01:51:40 +00:00
|
|
|
if self.is_html and self.shw_widget then
|
|
|
|
-- Re-use our ScrollHtmlWidget (self.shw_widget)
|
|
|
|
-- NOTE: The recursive free via our WidgetContainer (self[1]) above already released the previous MµPDF document instance ;)
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.text_widget.htmlbox_widget:setContent(self.definition, self:getHtmlDictionaryCss(), Screen:scaleBySize(self.dict_font_size))
|
2021-01-31 01:51:40 +00:00
|
|
|
-- Scroll back to top
|
|
|
|
self.text_widget:resetScroll()
|
|
|
|
elseif not self.is_html and self.stw_widget then
|
|
|
|
-- Re-use our ScrollTextWidget (self.stw_widget)
|
2021-02-16 12:20:32 +00:00
|
|
|
-- Update properties that may change across results (as done in DictQuickLookup:_instantiateScrollWidget())
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.text_widget.text_widget.text = self.definition
|
2021-02-16 12:20:32 +00:00
|
|
|
self.text_widget.text_widget.lang = self.lang and self.lang:lower()
|
|
|
|
self.text_widget.text_widget.para_direction_rtl = self.rtl_lang
|
|
|
|
self.text_widget.text_widget.images = self.images
|
2021-02-20 18:14:22 +00:00
|
|
|
-- Scroll back to the top, àla TextBoxWidget:scrollToTop
|
|
|
|
self.text_widget.text_widget.virtual_line_num = 1
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
-- NOTE: The recursive free via our WidgetContainer (self[1]) above already free'd us ;)
|
|
|
|
self.text_widget.text_widget:init()
|
2021-02-20 18:14:22 +00:00
|
|
|
-- Reset the scrollbar's state
|
2021-01-31 01:51:40 +00:00
|
|
|
self.text_widget:resetScroll()
|
|
|
|
else
|
|
|
|
-- We jumped from HTML to Text (or vice-versa), we need a new widget instance
|
|
|
|
self:_instantiateScrollWidget()
|
|
|
|
-- Update *all* the references to self.text_widget
|
|
|
|
self.definition_widget[1] = self.text_widget
|
|
|
|
-- Destroy the previous "opposite type" widget
|
|
|
|
if self.is_html then
|
|
|
|
self.stw_widget = nil
|
|
|
|
else
|
|
|
|
self.shw_widget = nil
|
|
|
|
end
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
end
|
|
|
|
|
2021-02-02 03:27:14 +00:00
|
|
|
-- If we're translucent, reset alpha to make the new definition actually readable.
|
|
|
|
if self.movable.alpha then
|
|
|
|
self.movable.alpha = nil
|
|
|
|
end
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "partial", self.dict_frame.dimen
|
|
|
|
end)
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
2020-12-22 17:45:29 +00:00
|
|
|
function DictQuickLookup:getInitialVisibleArea()
|
|
|
|
-- Some positionning happens only at paintTo() time, but we want
|
|
|
|
-- to know this before. So, do a bit like WidgetContainer does
|
|
|
|
-- (without any MovableContainer offset)
|
|
|
|
local dict_size = self.dict_frame:getSize()
|
|
|
|
local area = Geom:new{
|
|
|
|
w = dict_size.w,
|
|
|
|
h = dict_size.h,
|
|
|
|
x = self.region.x + math.floor((self.region.w - dict_size.w)/2)
|
|
|
|
}
|
|
|
|
if self.align == "top" then
|
|
|
|
area.y = self.region.y
|
|
|
|
elseif self.align == "bottom" then
|
|
|
|
area.y = self.region.y + self.region.h - dict_size.h
|
|
|
|
elseif self.align == "center" then
|
|
|
|
area.x = self.region.y + math.floor((self.region.h - dict_size.h)/2)
|
|
|
|
end
|
|
|
|
return area
|
|
|
|
end
|
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function DictQuickLookup:onCloseWidget()
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
-- Our TextBoxWidget/HtmlBoxWidget/TextWidget/ImageWidget are proper child widgets,
|
|
|
|
-- so this event will propagate to 'em, and they'll free their resources.
|
|
|
|
|
|
|
|
-- What's left is stuff that isn't directly in our widget tree...
|
2018-01-16 11:32:49 +00:00
|
|
|
if self.images_cleanup_needed then
|
|
|
|
logger.dbg("freeing lookup results images blitbuffers")
|
|
|
|
for _, r in ipairs(self.results) do
|
|
|
|
if r.images and #r.images > 0 then
|
|
|
|
for _, im in ipairs(r.images) do
|
|
|
|
if im.bb then im.bb:free() end
|
|
|
|
if im.hi_bb then im.hi_bb:free() end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-21 12:57:18 +00:00
|
|
|
|
2018-06-02 16:10:55 +00:00
|
|
|
-- NOTE: Drop region to make it a full-screen flash
|
2014-12-01 14:39:41 +00:00
|
|
|
UIManager:setDirty(nil, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "flashui", nil
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "flashui", self.dict_frame.dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-03-12 10:50:57 +00:00
|
|
|
function DictQuickLookup:getHighlightedItem()
|
2017-01-02 18:12:34 +00:00
|
|
|
if self:isDocless() then return end
|
2015-03-12 10:50:57 +00:00
|
|
|
return self.ui.highlight:getHighlightBookmarkItem()
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:getHighlightText()
|
|
|
|
local item = self:getHighlightedItem()
|
|
|
|
if not item then
|
2017-09-01 21:17:35 +00:00
|
|
|
return highlight_strings.highlight, false
|
2015-03-12 10:50:57 +00:00
|
|
|
elseif self.ui.bookmark:isBookmarkAdded(item) then
|
2017-09-01 21:17:35 +00:00
|
|
|
return highlight_strings.unhighlight, false
|
2015-03-12 10:50:57 +00:00
|
|
|
else
|
2017-09-01 21:17:35 +00:00
|
|
|
return highlight_strings.highlight, true
|
2015-03-12 10:50:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-21 06:23:54 +00:00
|
|
|
function DictQuickLookup:isPrevDictAvaiable()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.dict_index > 1
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:isNextDictAvaiable()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.dict_index < #self.results
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:changeToPrevDict()
|
2016-12-06 21:15:52 +00:00
|
|
|
if self:isPrevDictAvaiable() then
|
|
|
|
self:changeDictionary(self.dict_index - 1)
|
|
|
|
elseif #self.results > 1 then -- restart at end if first reached
|
|
|
|
self:changeDictionary(#self.results)
|
|
|
|
end
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:changeToNextDict()
|
2016-12-06 21:15:52 +00:00
|
|
|
if self:isNextDictAvaiable() then
|
|
|
|
self:changeDictionary(self.dict_index + 1)
|
|
|
|
elseif #self.results > 1 then -- restart at first if end reached
|
|
|
|
self:changeDictionary(1)
|
|
|
|
end
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
2021-01-01 13:34:53 +00:00
|
|
|
function DictQuickLookup:changeToFirstDict()
|
|
|
|
if self:isPrevDictAvaiable() then
|
|
|
|
self:changeDictionary(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:changeToLastDict()
|
|
|
|
if self:isNextDictAvaiable() then
|
|
|
|
self:changeDictionary(#self.results)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
function DictQuickLookup:changeDictionary(index, skip_update)
|
2014-07-24 14:10:28 +00:00
|
|
|
if not self.results[index] then return end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_index = index
|
|
|
|
self.dictionary = self.results[index].dict
|
|
|
|
self.lookupword = self.results[index].word
|
|
|
|
self.definition = self.results[index].definition
|
2020-12-22 17:45:34 +00:00
|
|
|
self.is_wiki_fullpage = self.results[index].is_wiki_fullpage
|
2018-01-07 19:24:15 +00:00
|
|
|
self.is_html = self.results[index].is_html
|
|
|
|
self.css = self.results[index].css
|
2017-01-21 18:23:13 +00:00
|
|
|
self.lang = self.results[index].lang
|
2019-12-06 21:55:35 +00:00
|
|
|
self.rtl_lang = self.results[index].rtl_lang
|
2018-01-16 11:32:49 +00:00
|
|
|
self.images = self.results[index].images
|
|
|
|
if self.images and #self.images > 0 then
|
|
|
|
-- We'll be giving some images to textboxwidget that will
|
|
|
|
-- load and display them. We'll need to free these blitbuffers
|
|
|
|
-- when we're done.
|
|
|
|
self.images_cleanup_needed = true
|
|
|
|
end
|
2020-12-22 17:45:34 +00:00
|
|
|
if self.is_wiki_fullpage then
|
2016-12-06 21:15:52 +00:00
|
|
|
self.displayword = self.lookupword
|
2020-12-22 17:45:34 +00:00
|
|
|
self.displaynb = nil
|
2016-12-06 21:15:52 +00:00
|
|
|
else
|
2020-12-22 17:45:34 +00:00
|
|
|
self.displayword = self.lookupword
|
|
|
|
-- show "dict_index / nbresults" so we know where we're at and what's yet to see
|
|
|
|
self.displaynb = T("%1 / %2", index, #self.results)
|
2016-12-06 21:15:52 +00:00
|
|
|
-- add queried word to 1st result's definition, so we can see
|
|
|
|
-- what was the selected text and if we selected wrong
|
|
|
|
if index == 1 then
|
2018-01-08 11:23:37 +00:00
|
|
|
if self.is_html then
|
|
|
|
self.definition = self.definition.."<br/>_______<br/>"
|
|
|
|
else
|
|
|
|
self.definition = self.definition.."\n_______\n"
|
|
|
|
end
|
|
|
|
self.definition = self.definition..T(_("(query : %1)"), self.word)
|
2016-12-06 21:15:52 +00:00
|
|
|
end
|
|
|
|
end
|
2021-01-06 20:49:23 +00:00
|
|
|
self.displaydictname = self.dictionary
|
|
|
|
if self.preferred_dictionaries then
|
|
|
|
-- If current result is from a preferred dictionary, prepend dict name
|
|
|
|
-- (shown in the window title) with its preference number
|
|
|
|
for idx, name in ipairs(self.preferred_dictionaries) do
|
|
|
|
if self.dictionary == name then
|
|
|
|
-- Use number in circle symbol (U+2460...2473)
|
|
|
|
local symbol = util.unicodeCodepointToUtf8(0x245F + (idx < 20 and idx or 20))
|
|
|
|
self.displaydictname = symbol .. " " .. self.displaydictname
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-05-01 10:37:12 +00:00
|
|
|
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
-- Don't call update when called from init
|
|
|
|
if not skip_update then
|
|
|
|
self:update()
|
|
|
|
end
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
2020-12-22 17:45:34 +00:00
|
|
|
--[[ No longer used
|
2014-05-01 10:37:12 +00:00
|
|
|
function DictQuickLookup:changeToDefaultDict()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.dictionary then
|
|
|
|
-- dictionaries that have definition of the first word(accurate word)
|
|
|
|
-- excluding Fuzzy queries.
|
|
|
|
local n_accurate_dicts = nil
|
|
|
|
local default_word = self.results[1].word
|
|
|
|
for i=1, #self.results do
|
|
|
|
if self.results[i].word == default_word then
|
|
|
|
n_accurate_dicts = i
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- change to dictionary specified by self.dictionary
|
|
|
|
for i=1, n_accurate_dicts do
|
|
|
|
if self.results[i].dict == self.dictionary then
|
|
|
|
self:changeDictionary(i)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
-- cannot find definition in default dictionary
|
|
|
|
if i == n_accurate_dicts then
|
|
|
|
self:changeDictionary(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self:changeDictionary(1)
|
|
|
|
end
|
2013-04-24 14:57:03 +00:00
|
|
|
end
|
2020-12-22 17:45:34 +00:00
|
|
|
]]--
|
2013-04-24 14:57:03 +00:00
|
|
|
|
2021-01-09 20:59:31 +00:00
|
|
|
function DictQuickLookup:onReadNextResult()
|
|
|
|
self:changeToNextDict()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onReadPrevResult()
|
|
|
|
local prev_index = self.dict_index
|
|
|
|
self:changeToPrevDict()
|
|
|
|
if self.dict_index ~= prev_index then
|
|
|
|
-- Jump directly to bottom of previous dict definition
|
|
|
|
-- to keep "continuous reading with tap" consistent
|
|
|
|
self.definition_widget[1]:scrollToRatio(1) -- 1 = 100% = bottom
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-04-24 14:57:03 +00:00
|
|
|
end
|
|
|
|
|
2020-12-22 17:45:34 +00:00
|
|
|
function DictQuickLookup:onTap(arg, ges_ev)
|
2014-03-13 13:52:43 +00:00
|
|
|
if ges_ev.pos:notIntersectWith(self.dict_frame.dimen) then
|
|
|
|
self:onClose()
|
|
|
|
return true
|
2020-12-22 17:45:34 +00:00
|
|
|
end
|
2021-01-06 20:49:23 +00:00
|
|
|
if ges_ev.pos:intersectWith(self.dict_title.dimen) and not self.is_wiki then
|
|
|
|
self.ui:handleEvent(Event:new("TogglePreferredDict", self.dictionary))
|
|
|
|
-- Re-display current result, with title bar updated
|
|
|
|
self:changeDictionary(self.dict_index)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2021-01-06 20:49:23 +00:00
|
|
|
end
|
2020-12-22 17:45:34 +00:00
|
|
|
if ges_ev.pos:intersectWith(self.definition_widget.dimen) then
|
|
|
|
-- Allow for changing dict with tap (tap event will be first
|
|
|
|
-- processed for scrolling definition by ScrollTextWidget, which
|
|
|
|
-- will pop it up for us here when it can't scroll anymore).
|
|
|
|
-- This allow for continuous reading of results' definitions with tap.
|
|
|
|
if BD.flipIfMirroredUILayout(ges_ev.pos.x < Screen:getWidth()/2) then
|
2021-01-09 20:59:31 +00:00
|
|
|
self:onReadPrevResult()
|
2020-12-22 17:45:34 +00:00
|
|
|
else
|
2021-01-09 20:59:31 +00:00
|
|
|
self:onReadNextResult()
|
2018-01-31 08:16:34 +00:00
|
|
|
end
|
2016-12-06 21:15:52 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-04-24 14:57:03 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2013-12-26 14:40:40 +00:00
|
|
|
function DictQuickLookup:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:close(self)
|
2016-06-28 16:35:00 +00:00
|
|
|
for i = #self.window_list, 1, -1 do
|
|
|
|
local window = self.window_list[i]
|
|
|
|
if window == self then
|
|
|
|
table.remove(self.window_list, i)
|
|
|
|
end
|
|
|
|
end
|
2014-08-17 16:32:09 +00:00
|
|
|
if self.highlight then
|
2016-12-06 21:15:52 +00:00
|
|
|
-- delay unhighlight of selection, so we can see where we stopped when
|
|
|
|
-- back from our journey into dictionary or wikipedia
|
2017-09-20 15:35:30 +00:00
|
|
|
local clear_id = self.highlight:getClearId()
|
2017-09-19 20:48:30 +00:00
|
|
|
UIManager:scheduleIn(0.5, function()
|
2017-09-20 15:35:30 +00:00
|
|
|
self.highlight:clear(clear_id)
|
2016-12-06 21:15:52 +00:00
|
|
|
end)
|
2016-06-28 16:35:00 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-01-21 18:23:13 +00:00
|
|
|
function DictQuickLookup:onHoldClose(no_clear)
|
2016-06-28 16:35:00 +00:00
|
|
|
self:onClose()
|
|
|
|
for i = #self.window_list, 1, -1 do
|
|
|
|
local window = self.window_list[i]
|
2016-12-06 21:15:52 +00:00
|
|
|
-- if one holds a highlight, let's clear it like in onClose()
|
2017-01-21 18:23:13 +00:00
|
|
|
if window.highlight and not no_clear then
|
2017-09-20 15:35:30 +00:00
|
|
|
local clear_id = window.highlight:getClearId()
|
|
|
|
UIManager:scheduleIn(0.5, function()
|
|
|
|
window.highlight:clear(clear_id)
|
2016-12-06 21:15:52 +00:00
|
|
|
end)
|
|
|
|
end
|
2016-06-28 16:35:00 +00:00
|
|
|
UIManager:close(window)
|
|
|
|
table.remove(self.window_list, i)
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-12-26 14:40:40 +00:00
|
|
|
end
|
|
|
|
|
2014-07-24 14:10:28 +00:00
|
|
|
function DictQuickLookup:onSwipe(arg, ges)
|
2018-01-29 20:27:24 +00:00
|
|
|
if ges.pos:intersectWith(self.definition_widget.dimen) then
|
|
|
|
-- if we want changeDict to still work with swipe outside window :
|
|
|
|
-- or not ges.pos:intersectWith(self.dict_frame.dimen) then
|
2019-12-06 21:55:39 +00:00
|
|
|
local direction = BD.flipDirectionIfMirroredUILayout(ges.direction)
|
|
|
|
if direction == "west" then
|
2018-01-29 20:27:24 +00:00
|
|
|
self:changeToNextDict()
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "east" then
|
2018-01-29 20:27:24 +00:00
|
|
|
self:changeToPrevDict()
|
|
|
|
else
|
|
|
|
if self.refresh_callback then self.refresh_callback() end
|
2020-11-16 14:48:27 +00:00
|
|
|
-- update footer (time & battery)
|
|
|
|
self.ui:handleEvent(Event:new("UpdateFooter", true))
|
2018-06-02 16:10:55 +00:00
|
|
|
-- trigger a full-screen HQ flashing refresh
|
2018-01-29 20:27:24 +00:00
|
|
|
UIManager:setDirty(nil, "full")
|
|
|
|
-- a long diagonal swipe may also be used for taking a screenshot,
|
|
|
|
-- so let it propagate
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
2014-07-24 14:10:28 +00:00
|
|
|
end
|
2018-01-29 20:27:24 +00:00
|
|
|
-- Let our MovableContainer handle swipe outside of definition
|
|
|
|
return self.movable:onMovableSwipe(arg, ges)
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onHoldStartText(_, ges)
|
|
|
|
-- Forward Hold events not processed by TextBoxWidget event handler
|
|
|
|
-- to our MovableContainer
|
|
|
|
return self.movable:onMovableHold(_, ges)
|
|
|
|
end
|
|
|
|
|
2018-03-07 14:59:59 +00:00
|
|
|
function DictQuickLookup:onHoldPanText(_, ges)
|
|
|
|
-- Forward Hold events not processed by TextBoxWidget event handler
|
|
|
|
-- to our MovableContainer
|
|
|
|
-- We only forward it if we did forward the Touch
|
|
|
|
if self.movable._touch_pre_pan_was_inside then
|
|
|
|
return self.movable:onMovableHoldPan(arg, ges)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-29 20:27:24 +00:00
|
|
|
function DictQuickLookup:onHoldReleaseText(_, ges)
|
|
|
|
-- Forward Hold events not processed by TextBoxWidget event handler
|
|
|
|
-- to our MovableContainer
|
|
|
|
return self.movable:onMovableHoldRelease(_, ges)
|
2014-07-24 14:10:28 +00:00
|
|
|
end
|
|
|
|
|
2018-03-07 14:59:59 +00:00
|
|
|
-- These 3 event processors are just used to forward these events
|
2018-03-05 20:27:55 +00:00
|
|
|
-- to our MovableContainer, under certain conditions, to avoid
|
|
|
|
-- unwanted moves of the window while we are selecting text in
|
|
|
|
-- the definition widget.
|
|
|
|
function DictQuickLookup:onForwardingTouch(arg, ges)
|
|
|
|
-- This Touch may be used as the Hold we don't get (for example,
|
|
|
|
-- when we start our Hold on the bottom buttons)
|
|
|
|
if not ges.pos:intersectWith(self.definition_widget.dimen) then
|
|
|
|
return self.movable:onMovableTouch(arg, ges)
|
|
|
|
else
|
|
|
|
-- Ensure this is unset, so we can use it to not forward HoldPan
|
|
|
|
self.movable._touch_pre_pan_was_inside = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onForwardingPan(arg, ges)
|
2018-03-07 14:59:59 +00:00
|
|
|
-- We only forward it if we did forward the Touch or are currently moving
|
|
|
|
if self.movable._touch_pre_pan_was_inside or self.movable._moving then
|
|
|
|
return self.movable:onMovablePan(arg, ges)
|
2018-03-05 20:27:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onForwardingPanRelease(arg, ges)
|
2018-03-07 14:59:59 +00:00
|
|
|
-- We can forward onMovablePanRelease() does enough checks
|
|
|
|
return self.movable:onMovablePanRelease(arg, ges)
|
2018-03-05 20:27:55 +00:00
|
|
|
end
|
|
|
|
|
2014-08-17 16:32:09 +00:00
|
|
|
function DictQuickLookup:lookupInputWord(hint)
|
|
|
|
self.input_dialog = InputDialog:new{
|
2021-04-02 15:59:29 +00:00
|
|
|
title = _("Enter a word or phrase to look up"),
|
2014-08-20 06:41:45 +00:00
|
|
|
input = hint,
|
2014-08-17 16:32:09 +00:00
|
|
|
input_hint = hint or "",
|
|
|
|
input_type = "text",
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
|
|
|
callback = function()
|
|
|
|
self:closeInputDialog()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2021-04-02 15:59:29 +00:00
|
|
|
text = self.is_wiki and _("Search Wikipedia") or _("Search dictionary"),
|
2016-05-26 06:09:49 +00:00
|
|
|
is_enter_default = true,
|
2014-08-17 16:32:09 +00:00
|
|
|
callback = function()
|
2021-04-04 15:27:17 +00:00
|
|
|
if self.input_dialog:getInputText() == "" then return end
|
2014-08-17 16:32:09 +00:00
|
|
|
self:closeInputDialog()
|
2020-12-22 17:45:34 +00:00
|
|
|
self:onClose()
|
2014-08-17 16:32:09 +00:00
|
|
|
self:inputLookup()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(self.input_dialog)
|
2018-03-30 10:46:36 +00:00
|
|
|
self.input_dialog:onShowKeyboard()
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:inputLookup()
|
|
|
|
local word = self.input_dialog:getInputText()
|
|
|
|
if word and word ~= "" then
|
2017-01-01 09:34:21 +00:00
|
|
|
local event
|
|
|
|
if self.is_wiki then
|
|
|
|
event = "LookupWikipedia"
|
|
|
|
self:resyncWikiLanguages()
|
|
|
|
else
|
|
|
|
event = "LookupWord"
|
|
|
|
end
|
2021-01-01 13:34:51 +00:00
|
|
|
-- Trust that input text does not need any cleaning (allows querying for "-suffix")
|
|
|
|
self.ui:handleEvent(Event:new(event, word, true))
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:closeInputDialog()
|
|
|
|
UIManager:close(self.input_dialog)
|
|
|
|
end
|
|
|
|
|
2017-01-01 09:34:21 +00:00
|
|
|
function DictQuickLookup:resyncWikiLanguages(rotate)
|
|
|
|
-- Resync the current language or rotate it from its state when
|
|
|
|
-- this window was created (we may have rotated it later in other
|
|
|
|
-- wikipedia windows that we closed and went back here, and its
|
|
|
|
-- state would not be what the wikipedia language button is showing.
|
|
|
|
if not self.wiki_languages_copy then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if rotate then
|
|
|
|
-- rotate our saved wiki_languages copy
|
|
|
|
local current_lang = table.remove(self.wiki_languages_copy, 1)
|
|
|
|
table.insert(self.wiki_languages_copy, current_lang)
|
|
|
|
end
|
|
|
|
-- re-set self.wiki_languages with original (possibly rotated) items
|
|
|
|
for i, lang in ipairs(self.wiki_languages_copy) do
|
|
|
|
self.wiki_languages[i] = lang
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-06 21:15:52 +00:00
|
|
|
function DictQuickLookup:lookupWikipedia(get_fullpage)
|
|
|
|
local word
|
2021-01-01 13:34:51 +00:00
|
|
|
local is_sane
|
2016-12-06 21:15:52 +00:00
|
|
|
if get_fullpage then
|
|
|
|
-- we use the word of the displayed result's definition, which
|
|
|
|
-- is the exact title of the full wikipedia page
|
|
|
|
word = self.lookupword
|
2021-01-01 13:34:51 +00:00
|
|
|
is_sane = true
|
2016-12-06 21:15:52 +00:00
|
|
|
else
|
|
|
|
-- we use the original word that was querried
|
|
|
|
word = self.word
|
2021-01-01 13:34:51 +00:00
|
|
|
is_sane = false
|
2016-12-06 21:15:52 +00:00
|
|
|
end
|
2017-01-01 09:34:21 +00:00
|
|
|
self:resyncWikiLanguages()
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
self.ui:handleEvent(Event:new("LookupWikipedia", word, is_sane, self.word_box, get_fullpage))
|
2014-08-20 06:41:45 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return DictQuickLookup
|