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 Button = require("ui/widget/button")
|
2016-12-29 07:27:48 +00:00
|
|
|
local Device = require("device")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Event = require("ui/event")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2021-01-18 10:59:04 +00:00
|
|
|
local FocusManager = require("ui/widget/focusmanager")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
2016-12-29 07:27:48 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2017-10-22 11:09:49 +00:00
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
2018-01-29 20:27:24 +00:00
|
|
|
local Math = require("optmath")
|
|
|
|
local MovableContainer = require("ui/widget/container/movablecontainer")
|
2016-12-29 07:27:48 +00:00
|
|
|
local ProgressWidget = require("ui/widget/progresswidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-04-29 08:38:09 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2016-12-29 07:27:48 +00:00
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2017-04-29 08:38:09 +00:00
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
local _ = require("gettext")
|
|
|
|
local Screen = Device.screen
|
2016-12-29 07:27:48 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local SkimToWidget = FocusManager:extend{}
|
2016-12-29 07:27:48 +00:00
|
|
|
|
|
|
|
function SkimToWidget:init()
|
2021-02-20 18:09:57 +00:00
|
|
|
local screen_width = Screen:getWidth()
|
|
|
|
local screen_height = Screen:getHeight()
|
|
|
|
|
2016-12-29 07:27:48 +00:00
|
|
|
if Device:hasKeys() then
|
2022-10-27 00:01:51 +00:00
|
|
|
self.key_events.Close = { { Device.input.group.Back } }
|
2016-12-29 07:27:48 +00:00
|
|
|
end
|
|
|
|
if Device:isTouchDevice() then
|
2022-10-27 00:01:51 +00:00
|
|
|
self.ges_events.TapProgress = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = screen_width,
|
|
|
|
h = screen_height,
|
|
|
|
}
|
2016-12-29 07:27:48 +00:00
|
|
|
},
|
2022-10-27 00:01:51 +00:00
|
|
|
}
|
2016-12-29 07:27:48 +00:00
|
|
|
end
|
|
|
|
|
2021-02-20 18:09:57 +00:00
|
|
|
self.buttons_layout = {}
|
2020-03-26 13:04:59 +00:00
|
|
|
|
2021-09-25 08:51:58 +00:00
|
|
|
local frame_width = math.floor(math.min(screen_width, screen_height) * 0.95)
|
2021-02-20 18:09:57 +00:00
|
|
|
local frame_border_size = Size.border.window
|
|
|
|
local frame_padding = Size.padding.fullscreen -- large padding for airy feeling
|
|
|
|
local inner_width = frame_width - 2 * (frame_border_size + frame_padding)
|
2017-10-22 11:09:49 +00:00
|
|
|
|
2021-02-20 18:09:57 +00:00
|
|
|
-- In this inner width, we'll be showing 5 buttons, with the middle one
|
|
|
|
-- separated a bit more from the others
|
|
|
|
local button_span_unit_width = Size.span.horizontal_small
|
|
|
|
local larger_span_units = 3 -- 3 x small span width
|
|
|
|
local nb_span_units = 2 + 2*larger_span_units
|
2022-10-10 20:21:27 +00:00
|
|
|
local button_width = math.floor( (inner_width - nb_span_units * button_span_unit_width) * (1/5))
|
2021-02-20 18:09:57 +00:00
|
|
|
-- Update inner_width (possibly smaller because of math.floor())
|
|
|
|
inner_width = button_width * 5 + nb_span_units * button_span_unit_width
|
|
|
|
|
|
|
|
self.curr_page = self.ui:getCurrentPage()
|
|
|
|
self.page_count = self.document:getPageCount()
|
|
|
|
self.ticks_flattened = self.ui.toc:getTocTicksFlattened()
|
2016-12-29 07:27:48 +00:00
|
|
|
|
2017-10-22 11:09:49 +00:00
|
|
|
self.progress_bar = ProgressWidget:new{
|
2021-02-20 18:09:57 +00:00
|
|
|
width = inner_width,
|
2019-09-26 22:38:44 +00:00
|
|
|
height = Size.item.height_big,
|
2016-12-29 07:27:48 +00:00
|
|
|
percentage = self.curr_page / self.page_count,
|
2020-09-27 20:25:16 +00:00
|
|
|
ticks = self.ticks_flattened,
|
2017-10-22 11:09:49 +00:00
|
|
|
tick_width = Size.line.medium,
|
|
|
|
last = self.page_count,
|
2020-10-31 09:40:36 +00:00
|
|
|
alt = self.ui.document.flows,
|
2023-02-16 23:37:30 +00:00
|
|
|
initial_pos_marker = true,
|
2016-12-29 07:27:48 +00:00
|
|
|
}
|
|
|
|
|
2021-02-20 18:09:57 +00:00
|
|
|
-- Bottom row buttons
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_minus = Button:new{
|
2016-12-29 07:27:48 +00:00
|
|
|
text = "-1",
|
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2016-12-29 07:27:48 +00:00
|
|
|
show_parent = self,
|
Revamp "flash_ui" handling (#7118)
* Wherever possible, do an actual dumb invert on the Screen BB instead of repainting the widget, *then* inverting it (which is what the "invert" flag does).
* Instead of playing with nextTick/tickAfterNext delays, explicitly fence stuff with forceRePaint
* And, in the few cases where said Mk. 7 quirk kicks in, make the fences more marked by using a well-placed WAIT_FOR_UPDATE_COMPLETE
* Fix an issue in Button where show/hide & enable/disable where actually all toggles, which meant that duplicate calls or timing issues would do the wrong thing. (This broke dimming some icons, and mistakenly dropped the background from FM chevrons, for example).
* Speaking of, fix Button's hide/show to actually restore the background properly (there was a stupid typo in the variable name)
* Still in Button, fix the insanity of the double repaint on rounded buttons. Turns out it made sense, after all (and was related to said missing background, and bad interaction with invert & text with no background).
* KeyValuePage suffered from a similar issue with broken highlights (all black) because of missing backgrounds.
* In ConfigDialog, only instanciate IconButtons once (because every tab switch causes a full instantiation; and the initial display implies a full instanciation and an initial tab switch). Otherwise, both instances linger, and catch taps, and as such, double highlights.
* ConfigDialog: Restore the "don't repaint ReaderUI" when switching between similarly sized tabs (re #6131). I never could reproduce that on eInk, and I can't now on the emulator, so I'm assuming @poire-z fixed it during the swap to SVG icons.
* KeyValuePage: Only instanciate Buttons once (again, this is a widget that goes through a full init every page). Again, caused highlight/dimming issues because buttons were stacked.
* Menu: Ditto.
* TouchMenu: Now home of the gnarliest unhilight heuristics, because of the sheer amount of different things that can happen (and/or thanks to stuff not flagged covers_fullscreen properly ;p).
* Bump base
https://github.com/koreader/koreader-base/pull/1280
https://github.com/koreader/koreader-base/pull/1282
https://github.com/koreader/koreader-base/pull/1283
https://github.com/koreader/koreader-base/pull/1284
* Bump android-luajit-launcher
https://github.com/koreader/android-luajit-launcher/pull/284
https://github.com/koreader/android-luajit-launcher/pull/285
https://github.com/koreader/android-luajit-launcher/pull/286
https://github.com/koreader/android-luajit-launcher/pull/287
2021-01-10 00:51:09 +00:00
|
|
|
vsync = true,
|
2016-12-29 07:27:48 +00:00
|
|
|
callback = function()
|
2020-02-09 12:00:57 +00:00
|
|
|
self:goToPage(self.curr_page - 1)
|
2016-12-29 07:27:48 +00:00
|
|
|
end,
|
|
|
|
}
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_minus_ten = Button:new{
|
2016-12-29 07:27:48 +00:00
|
|
|
text = "-10",
|
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2016-12-29 07:27:48 +00:00
|
|
|
show_parent = self,
|
Revamp "flash_ui" handling (#7118)
* Wherever possible, do an actual dumb invert on the Screen BB instead of repainting the widget, *then* inverting it (which is what the "invert" flag does).
* Instead of playing with nextTick/tickAfterNext delays, explicitly fence stuff with forceRePaint
* And, in the few cases where said Mk. 7 quirk kicks in, make the fences more marked by using a well-placed WAIT_FOR_UPDATE_COMPLETE
* Fix an issue in Button where show/hide & enable/disable where actually all toggles, which meant that duplicate calls or timing issues would do the wrong thing. (This broke dimming some icons, and mistakenly dropped the background from FM chevrons, for example).
* Speaking of, fix Button's hide/show to actually restore the background properly (there was a stupid typo in the variable name)
* Still in Button, fix the insanity of the double repaint on rounded buttons. Turns out it made sense, after all (and was related to said missing background, and bad interaction with invert & text with no background).
* KeyValuePage suffered from a similar issue with broken highlights (all black) because of missing backgrounds.
* In ConfigDialog, only instanciate IconButtons once (because every tab switch causes a full instantiation; and the initial display implies a full instanciation and an initial tab switch). Otherwise, both instances linger, and catch taps, and as such, double highlights.
* ConfigDialog: Restore the "don't repaint ReaderUI" when switching between similarly sized tabs (re #6131). I never could reproduce that on eInk, and I can't now on the emulator, so I'm assuming @poire-z fixed it during the swap to SVG icons.
* KeyValuePage: Only instanciate Buttons once (again, this is a widget that goes through a full init every page). Again, caused highlight/dimming issues because buttons were stacked.
* Menu: Ditto.
* TouchMenu: Now home of the gnarliest unhilight heuristics, because of the sheer amount of different things that can happen (and/or thanks to stuff not flagged covers_fullscreen properly ;p).
* Bump base
https://github.com/koreader/koreader-base/pull/1280
https://github.com/koreader/koreader-base/pull/1282
https://github.com/koreader/koreader-base/pull/1283
https://github.com/koreader/koreader-base/pull/1284
* Bump android-luajit-launcher
https://github.com/koreader/android-luajit-launcher/pull/284
https://github.com/koreader/android-luajit-launcher/pull/285
https://github.com/koreader/android-luajit-launcher/pull/286
https://github.com/koreader/android-luajit-launcher/pull/287
2021-01-10 00:51:09 +00:00
|
|
|
vsync = true,
|
2016-12-29 07:27:48 +00:00
|
|
|
callback = function()
|
2020-02-09 12:00:57 +00:00
|
|
|
self:goToPage(self.curr_page - 10)
|
2016-12-29 07:27:48 +00:00
|
|
|
end,
|
|
|
|
}
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_plus = Button:new{
|
2016-12-29 07:27:48 +00:00
|
|
|
text = "+1",
|
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2016-12-29 07:27:48 +00:00
|
|
|
show_parent = self,
|
Revamp "flash_ui" handling (#7118)
* Wherever possible, do an actual dumb invert on the Screen BB instead of repainting the widget, *then* inverting it (which is what the "invert" flag does).
* Instead of playing with nextTick/tickAfterNext delays, explicitly fence stuff with forceRePaint
* And, in the few cases where said Mk. 7 quirk kicks in, make the fences more marked by using a well-placed WAIT_FOR_UPDATE_COMPLETE
* Fix an issue in Button where show/hide & enable/disable where actually all toggles, which meant that duplicate calls or timing issues would do the wrong thing. (This broke dimming some icons, and mistakenly dropped the background from FM chevrons, for example).
* Speaking of, fix Button's hide/show to actually restore the background properly (there was a stupid typo in the variable name)
* Still in Button, fix the insanity of the double repaint on rounded buttons. Turns out it made sense, after all (and was related to said missing background, and bad interaction with invert & text with no background).
* KeyValuePage suffered from a similar issue with broken highlights (all black) because of missing backgrounds.
* In ConfigDialog, only instanciate IconButtons once (because every tab switch causes a full instantiation; and the initial display implies a full instanciation and an initial tab switch). Otherwise, both instances linger, and catch taps, and as such, double highlights.
* ConfigDialog: Restore the "don't repaint ReaderUI" when switching between similarly sized tabs (re #6131). I never could reproduce that on eInk, and I can't now on the emulator, so I'm assuming @poire-z fixed it during the swap to SVG icons.
* KeyValuePage: Only instanciate Buttons once (again, this is a widget that goes through a full init every page). Again, caused highlight/dimming issues because buttons were stacked.
* Menu: Ditto.
* TouchMenu: Now home of the gnarliest unhilight heuristics, because of the sheer amount of different things that can happen (and/or thanks to stuff not flagged covers_fullscreen properly ;p).
* Bump base
https://github.com/koreader/koreader-base/pull/1280
https://github.com/koreader/koreader-base/pull/1282
https://github.com/koreader/koreader-base/pull/1283
https://github.com/koreader/koreader-base/pull/1284
* Bump android-luajit-launcher
https://github.com/koreader/android-luajit-launcher/pull/284
https://github.com/koreader/android-luajit-launcher/pull/285
https://github.com/koreader/android-luajit-launcher/pull/286
https://github.com/koreader/android-luajit-launcher/pull/287
2021-01-10 00:51:09 +00:00
|
|
|
vsync = true,
|
2016-12-29 07:27:48 +00:00
|
|
|
callback = function()
|
2020-02-09 12:00:57 +00:00
|
|
|
self:goToPage(self.curr_page + 1)
|
2016-12-29 07:27:48 +00:00
|
|
|
end,
|
|
|
|
}
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_plus_ten = Button:new{
|
2016-12-29 07:27:48 +00:00
|
|
|
text = "+10",
|
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2016-12-29 07:27:48 +00:00
|
|
|
show_parent = self,
|
Revamp "flash_ui" handling (#7118)
* Wherever possible, do an actual dumb invert on the Screen BB instead of repainting the widget, *then* inverting it (which is what the "invert" flag does).
* Instead of playing with nextTick/tickAfterNext delays, explicitly fence stuff with forceRePaint
* And, in the few cases where said Mk. 7 quirk kicks in, make the fences more marked by using a well-placed WAIT_FOR_UPDATE_COMPLETE
* Fix an issue in Button where show/hide & enable/disable where actually all toggles, which meant that duplicate calls or timing issues would do the wrong thing. (This broke dimming some icons, and mistakenly dropped the background from FM chevrons, for example).
* Speaking of, fix Button's hide/show to actually restore the background properly (there was a stupid typo in the variable name)
* Still in Button, fix the insanity of the double repaint on rounded buttons. Turns out it made sense, after all (and was related to said missing background, and bad interaction with invert & text with no background).
* KeyValuePage suffered from a similar issue with broken highlights (all black) because of missing backgrounds.
* In ConfigDialog, only instanciate IconButtons once (because every tab switch causes a full instantiation; and the initial display implies a full instanciation and an initial tab switch). Otherwise, both instances linger, and catch taps, and as such, double highlights.
* ConfigDialog: Restore the "don't repaint ReaderUI" when switching between similarly sized tabs (re #6131). I never could reproduce that on eInk, and I can't now on the emulator, so I'm assuming @poire-z fixed it during the swap to SVG icons.
* KeyValuePage: Only instanciate Buttons once (again, this is a widget that goes through a full init every page). Again, caused highlight/dimming issues because buttons were stacked.
* Menu: Ditto.
* TouchMenu: Now home of the gnarliest unhilight heuristics, because of the sheer amount of different things that can happen (and/or thanks to stuff not flagged covers_fullscreen properly ;p).
* Bump base
https://github.com/koreader/koreader-base/pull/1280
https://github.com/koreader/koreader-base/pull/1282
https://github.com/koreader/koreader-base/pull/1283
https://github.com/koreader/koreader-base/pull/1284
* Bump android-luajit-launcher
https://github.com/koreader/android-luajit-launcher/pull/284
https://github.com/koreader/android-luajit-launcher/pull/285
https://github.com/koreader/android-luajit-launcher/pull/286
https://github.com/koreader/android-luajit-launcher/pull/287
2021-01-10 00:51:09 +00:00
|
|
|
vsync = true,
|
2016-12-29 07:27:48 +00:00
|
|
|
callback = function()
|
2020-02-09 12:00:57 +00:00
|
|
|
self:goToPage(self.curr_page + 10)
|
2016-12-29 07:27:48 +00:00
|
|
|
end,
|
|
|
|
}
|
2017-10-22 11:09:49 +00:00
|
|
|
self.current_page_text = Button:new{
|
2021-02-20 18:09:57 +00:00
|
|
|
text_func = function()
|
|
|
|
local curr_page_display = tostring(self.curr_page)
|
|
|
|
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
|
|
|
|
curr_page_display = self.ui.pagemap:getCurrentPageLabel(true)
|
|
|
|
end
|
|
|
|
return curr_page_display
|
|
|
|
end,
|
2016-12-29 07:27:48 +00:00
|
|
|
radius = 0,
|
2017-10-22 11:09:49 +00:00
|
|
|
padding = 0,
|
2021-02-20 18:09:57 +00:00
|
|
|
bordersize = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2016-12-29 07:27:48 +00:00
|
|
|
show_parent = self,
|
|
|
|
callback = function()
|
|
|
|
self.callback_switch_to_goto()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
2021-02-20 18:09:57 +00:00
|
|
|
-- Top row buttons
|
2021-02-22 01:09:44 +00:00
|
|
|
local chapter_next_text = "▷▏"
|
|
|
|
local chapter_prev_text = "▕◁"
|
2019-12-06 21:55:39 +00:00
|
|
|
local bookmark_next_text = "☆▷"
|
|
|
|
local bookmark_prev_text = "◁☆"
|
2021-02-20 18:09:57 +00:00
|
|
|
local bookmark_enabled_text = "★"
|
|
|
|
local bookmark_disabled_text = "☆"
|
2019-12-06 21:55:39 +00:00
|
|
|
if BD.mirroredUILayout() then
|
|
|
|
chapter_next_text, chapter_prev_text = chapter_prev_text, chapter_next_text
|
|
|
|
bookmark_next_text, bookmark_prev_text = bookmark_prev_text, bookmark_next_text
|
|
|
|
end
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_chapter_next = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
text = chapter_next_text,
|
2017-10-22 11:09:49 +00:00
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2017-10-22 11:09:49 +00:00
|
|
|
show_parent = self,
|
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
|
|
|
vsync = true,
|
2017-10-22 11:09:49 +00:00
|
|
|
callback = function()
|
2020-09-27 20:25:16 +00:00
|
|
|
local page = self.ui.toc:getNextChapter(self.curr_page)
|
2017-10-22 11:09:49 +00:00
|
|
|
if page and page >=1 and page <= self.page_count then
|
2020-02-09 12:00:57 +00:00
|
|
|
self:goToPage(page)
|
2017-10-22 11:09:49 +00:00
|
|
|
end
|
|
|
|
end,
|
2020-02-09 12:00:57 +00:00
|
|
|
hold_callback = function()
|
|
|
|
self:goToPage(self.page_count)
|
|
|
|
end,
|
2016-12-29 07:27:48 +00:00
|
|
|
}
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_chapter_prev = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
text = chapter_prev_text,
|
2017-10-22 11:09:49 +00:00
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2017-10-22 11:09:49 +00:00
|
|
|
show_parent = self,
|
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
|
|
|
vsync = true,
|
2017-10-22 11:09:49 +00:00
|
|
|
callback = function()
|
2020-09-27 20:25:16 +00:00
|
|
|
local page = self.ui.toc:getPreviousChapter(self.curr_page)
|
2017-10-22 11:09:49 +00:00
|
|
|
if page and page >=1 and page <= self.page_count then
|
2020-02-09 12:00:57 +00:00
|
|
|
self:goToPage(page)
|
2017-10-22 11:09:49 +00:00
|
|
|
end
|
|
|
|
end,
|
2020-02-09 12:00:57 +00:00
|
|
|
hold_callback = function()
|
|
|
|
self:goToPage(1)
|
|
|
|
end,
|
2016-12-29 07:27:48 +00:00
|
|
|
}
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_bookmark_next = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
text = bookmark_next_text,
|
2017-10-22 11:09:49 +00:00
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2017-10-22 11:09:49 +00:00
|
|
|
show_parent = self,
|
Revamp "flash_ui" handling (#7118)
* Wherever possible, do an actual dumb invert on the Screen BB instead of repainting the widget, *then* inverting it (which is what the "invert" flag does).
* Instead of playing with nextTick/tickAfterNext delays, explicitly fence stuff with forceRePaint
* And, in the few cases where said Mk. 7 quirk kicks in, make the fences more marked by using a well-placed WAIT_FOR_UPDATE_COMPLETE
* Fix an issue in Button where show/hide & enable/disable where actually all toggles, which meant that duplicate calls or timing issues would do the wrong thing. (This broke dimming some icons, and mistakenly dropped the background from FM chevrons, for example).
* Speaking of, fix Button's hide/show to actually restore the background properly (there was a stupid typo in the variable name)
* Still in Button, fix the insanity of the double repaint on rounded buttons. Turns out it made sense, after all (and was related to said missing background, and bad interaction with invert & text with no background).
* KeyValuePage suffered from a similar issue with broken highlights (all black) because of missing backgrounds.
* In ConfigDialog, only instanciate IconButtons once (because every tab switch causes a full instantiation; and the initial display implies a full instanciation and an initial tab switch). Otherwise, both instances linger, and catch taps, and as such, double highlights.
* ConfigDialog: Restore the "don't repaint ReaderUI" when switching between similarly sized tabs (re #6131). I never could reproduce that on eInk, and I can't now on the emulator, so I'm assuming @poire-z fixed it during the swap to SVG icons.
* KeyValuePage: Only instanciate Buttons once (again, this is a widget that goes through a full init every page). Again, caused highlight/dimming issues because buttons were stacked.
* Menu: Ditto.
* TouchMenu: Now home of the gnarliest unhilight heuristics, because of the sheer amount of different things that can happen (and/or thanks to stuff not flagged covers_fullscreen properly ;p).
* Bump base
https://github.com/koreader/koreader-base/pull/1280
https://github.com/koreader/koreader-base/pull/1282
https://github.com/koreader/koreader-base/pull/1283
https://github.com/koreader/koreader-base/pull/1284
* Bump android-luajit-launcher
https://github.com/koreader/android-luajit-launcher/pull/284
https://github.com/koreader/android-luajit-launcher/pull/285
https://github.com/koreader/android-luajit-launcher/pull/286
https://github.com/koreader/android-luajit-launcher/pull/287
2021-01-10 00:51:09 +00:00
|
|
|
vsync = true,
|
2017-10-22 11:09:49 +00:00
|
|
|
callback = function()
|
2020-06-01 05:13:58 +00:00
|
|
|
self:goToByEvent("GotoNextBookmarkFromPage")
|
2020-02-09 12:00:57 +00:00
|
|
|
end,
|
|
|
|
hold_callback = function()
|
2023-09-15 04:24:31 +00:00
|
|
|
self:goToByEvent("GotoLastBookmark")
|
2017-10-22 11:09:49 +00:00
|
|
|
end,
|
2016-12-29 07:27:48 +00:00
|
|
|
}
|
2017-10-22 11:09:49 +00:00
|
|
|
local button_bookmark_prev = Button:new{
|
2019-12-06 21:55:39 +00:00
|
|
|
text = bookmark_prev_text,
|
2016-12-29 07:27:48 +00:00
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2016-12-29 07:27:48 +00:00
|
|
|
show_parent = self,
|
Revamp "flash_ui" handling (#7118)
* Wherever possible, do an actual dumb invert on the Screen BB instead of repainting the widget, *then* inverting it (which is what the "invert" flag does).
* Instead of playing with nextTick/tickAfterNext delays, explicitly fence stuff with forceRePaint
* And, in the few cases where said Mk. 7 quirk kicks in, make the fences more marked by using a well-placed WAIT_FOR_UPDATE_COMPLETE
* Fix an issue in Button where show/hide & enable/disable where actually all toggles, which meant that duplicate calls or timing issues would do the wrong thing. (This broke dimming some icons, and mistakenly dropped the background from FM chevrons, for example).
* Speaking of, fix Button's hide/show to actually restore the background properly (there was a stupid typo in the variable name)
* Still in Button, fix the insanity of the double repaint on rounded buttons. Turns out it made sense, after all (and was related to said missing background, and bad interaction with invert & text with no background).
* KeyValuePage suffered from a similar issue with broken highlights (all black) because of missing backgrounds.
* In ConfigDialog, only instanciate IconButtons once (because every tab switch causes a full instantiation; and the initial display implies a full instanciation and an initial tab switch). Otherwise, both instances linger, and catch taps, and as such, double highlights.
* ConfigDialog: Restore the "don't repaint ReaderUI" when switching between similarly sized tabs (re #6131). I never could reproduce that on eInk, and I can't now on the emulator, so I'm assuming @poire-z fixed it during the swap to SVG icons.
* KeyValuePage: Only instanciate Buttons once (again, this is a widget that goes through a full init every page). Again, caused highlight/dimming issues because buttons were stacked.
* Menu: Ditto.
* TouchMenu: Now home of the gnarliest unhilight heuristics, because of the sheer amount of different things that can happen (and/or thanks to stuff not flagged covers_fullscreen properly ;p).
* Bump base
https://github.com/koreader/koreader-base/pull/1280
https://github.com/koreader/koreader-base/pull/1282
https://github.com/koreader/koreader-base/pull/1283
https://github.com/koreader/koreader-base/pull/1284
* Bump android-luajit-launcher
https://github.com/koreader/android-luajit-launcher/pull/284
https://github.com/koreader/android-luajit-launcher/pull/285
https://github.com/koreader/android-luajit-launcher/pull/286
https://github.com/koreader/android-luajit-launcher/pull/287
2021-01-10 00:51:09 +00:00
|
|
|
vsync = true,
|
2016-12-29 07:27:48 +00:00
|
|
|
callback = function()
|
2020-06-01 05:13:58 +00:00
|
|
|
self:goToByEvent("GotoPreviousBookmarkFromPage")
|
2020-02-09 12:00:57 +00:00
|
|
|
end,
|
|
|
|
hold_callback = function()
|
2023-09-15 04:24:31 +00:00
|
|
|
self:goToByEvent("GotoFirstBookmark")
|
2016-12-29 07:27:48 +00:00
|
|
|
end,
|
|
|
|
}
|
2021-02-20 18:09:57 +00:00
|
|
|
self.button_bookmark_toggle = Button:new{
|
|
|
|
text_func = function()
|
|
|
|
return self.ui.view.dogear_visible and bookmark_enabled_text or bookmark_disabled_text
|
|
|
|
end,
|
|
|
|
radius = 0,
|
2023-03-23 17:37:29 +00:00
|
|
|
width = button_width,
|
2021-02-20 18:09:57 +00:00
|
|
|
show_parent = self,
|
|
|
|
callback = function()
|
|
|
|
self.ui:handleEvent(Event:new("ToggleBookmark"))
|
|
|
|
self:update()
|
|
|
|
end,
|
|
|
|
hold_callback = function()
|
|
|
|
self.ui:handleEvent(Event:new("ShowBookmark"))
|
|
|
|
UIManager:close(self)
|
|
|
|
end,
|
|
|
|
}
|
2016-12-29 07:27:48 +00:00
|
|
|
|
2021-02-20 18:09:57 +00:00
|
|
|
local row_span = VerticalSpan:new{ width = Size.padding.fullscreen }
|
|
|
|
local small_button_span = HorizontalSpan:new{ width = button_span_unit_width }
|
|
|
|
local large_button_span = HorizontalSpan:new{ width = button_span_unit_width * larger_span_units }
|
|
|
|
|
|
|
|
local top_buttons_row = HorizontalGroup:new{
|
2017-10-22 11:09:49 +00:00
|
|
|
align = "center",
|
|
|
|
button_chapter_prev,
|
2021-02-20 18:09:57 +00:00
|
|
|
small_button_span,
|
2017-10-22 11:09:49 +00:00
|
|
|
button_bookmark_prev,
|
2021-02-20 18:09:57 +00:00
|
|
|
large_button_span,
|
|
|
|
self.button_bookmark_toggle,
|
|
|
|
large_button_span,
|
2017-10-22 11:09:49 +00:00
|
|
|
button_bookmark_next,
|
2021-02-20 18:09:57 +00:00
|
|
|
small_button_span,
|
2017-10-22 11:09:49 +00:00
|
|
|
button_chapter_next,
|
|
|
|
}
|
2021-02-20 18:09:57 +00:00
|
|
|
local bottom_buttons_row = HorizontalGroup:new{
|
2016-12-29 07:27:48 +00:00
|
|
|
align = "center",
|
2017-10-22 11:09:49 +00:00
|
|
|
button_minus_ten,
|
2021-03-13 23:10:30 +00:00
|
|
|
small_button_span,
|
|
|
|
button_minus,
|
2021-02-20 18:09:57 +00:00
|
|
|
large_button_span,
|
2017-10-22 11:09:49 +00:00
|
|
|
self.current_page_text,
|
2021-02-20 18:09:57 +00:00
|
|
|
large_button_span,
|
2017-10-22 11:09:49 +00:00
|
|
|
button_plus,
|
2021-03-13 23:10:30 +00:00
|
|
|
small_button_span,
|
|
|
|
button_plus_ten,
|
2016-12-29 07:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.skimto_frame = FrameContainer:new{
|
|
|
|
margin = 0,
|
2021-02-20 18:09:57 +00:00
|
|
|
bordersize = frame_border_size,
|
|
|
|
padding = frame_padding,
|
|
|
|
radius = Size.radius.window,
|
2016-12-29 07:27:48 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
VerticalGroup:new{
|
|
|
|
align = "center",
|
2021-02-20 18:09:57 +00:00
|
|
|
top_buttons_row,
|
|
|
|
row_span,
|
|
|
|
self.progress_bar,
|
|
|
|
row_span,
|
|
|
|
bottom_buttons_row,
|
2016-12-29 07:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-02 03:27:14 +00:00
|
|
|
self.movable = MovableContainer:new{
|
|
|
|
self.skimto_frame,
|
|
|
|
}
|
2016-12-29 07:27:48 +00:00
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
align = "center",
|
|
|
|
dimen =Geom:new{
|
|
|
|
x = 0, y = 0,
|
2021-02-20 18:09:57 +00:00
|
|
|
w = screen_width,
|
|
|
|
h = screen_height,
|
2016-12-29 07:27:48 +00:00
|
|
|
},
|
2021-02-02 03:27:14 +00:00
|
|
|
self.movable,
|
2016-12-29 07:27:48 +00:00
|
|
|
}
|
2021-01-18 10:59:04 +00:00
|
|
|
|
|
|
|
if Device:hasDPad() then
|
|
|
|
self.buttons_layout = {
|
2021-02-20 18:09:57 +00:00
|
|
|
{ button_chapter_prev, button_bookmark_prev, self.button_bookmark_toggle, button_bookmark_next, button_chapter_next },
|
2021-03-13 23:10:30 +00:00
|
|
|
{ button_minus_ten, button_minus, self.current_page_text, button_plus, button_plus_ten },
|
2021-01-18 10:59:04 +00:00
|
|
|
}
|
|
|
|
self.layout = self.buttons_layout
|
2022-03-04 20:20:00 +00:00
|
|
|
self:moveFocusTo(1, 2)
|
2021-01-18 10:59:04 +00:00
|
|
|
end
|
|
|
|
if Device:hasKeyboard() then
|
|
|
|
self.key_events.QKey = { { "Q" }, event = "FirstRowKeyPress", args = 0 }
|
|
|
|
self.key_events.WKey = { { "W" }, event = "FirstRowKeyPress", args = 0.11 }
|
|
|
|
self.key_events.EKey = { { "E" }, event = "FirstRowKeyPress", args = 0.22 }
|
|
|
|
self.key_events.RKey = { { "R" }, event = "FirstRowKeyPress", args = 0.33 }
|
|
|
|
self.key_events.TKey = { { "T" }, event = "FirstRowKeyPress", args = 0.44 }
|
|
|
|
self.key_events.YKey = { { "Y" }, event = "FirstRowKeyPress", args = 0.55 }
|
|
|
|
self.key_events.UKey = { { "U" }, event = "FirstRowKeyPress", args = 0.66 }
|
|
|
|
self.key_events.IKey = { { "I" }, event = "FirstRowKeyPress", args = 0.77 }
|
|
|
|
self.key_events.OKey = { { "O" }, event = "FirstRowKeyPress", args = 0.88 }
|
|
|
|
self.key_events.PKey = { { "P" }, event = "FirstRowKeyPress", args = 1 }
|
|
|
|
end
|
2016-12-29 07:27:48 +00:00
|
|
|
end
|
|
|
|
|
2017-10-22 11:09:49 +00:00
|
|
|
function SkimToWidget:update()
|
|
|
|
if self.curr_page <= 0 then
|
|
|
|
self.curr_page = 1
|
|
|
|
end
|
|
|
|
if self.curr_page > self.page_count then
|
|
|
|
self.curr_page = self.page_count
|
|
|
|
end
|
|
|
|
self.progress_bar.percentage = self.curr_page / self.page_count
|
2021-02-20 18:09:57 +00:00
|
|
|
self.current_page_text:setText(self.current_page_text:text_func(), self.current_page_text.width)
|
|
|
|
self.button_bookmark_toggle:setText(self.button_bookmark_toggle:text_func(), self.button_bookmark_toggle.width)
|
2022-03-04 20:20:00 +00:00
|
|
|
self:refocusWidget(FocusManager.RENDER_IN_NEXT_TICK)
|
2017-10-22 11:09:49 +00:00
|
|
|
end
|
|
|
|
|
2018-08-15 13:22:55 +00:00
|
|
|
function SkimToWidget:addOriginToLocationStack(add_current)
|
|
|
|
-- Only add the page from which we launched the SkimToWidget
|
|
|
|
-- to the location stack, unless add_current = true
|
|
|
|
if not self.orig_page_added_to_stack or add_current then
|
|
|
|
self.ui.link:addCurrentLocationToStack()
|
|
|
|
self.orig_page_added_to_stack = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-29 07:27:48 +00:00
|
|
|
function SkimToWidget:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
2017-10-22 11:09:49 +00:00
|
|
|
return "ui", self.skimto_frame.dimen
|
2016-12-29 07:27:48 +00:00
|
|
|
end)
|
2023-02-16 23:37:30 +00:00
|
|
|
|
|
|
|
self:free()
|
2016-12-29 07:27:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function SkimToWidget:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.skimto_frame.dimen
|
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-02-09 12:00:57 +00:00
|
|
|
function SkimToWidget:goToPage(page)
|
|
|
|
self.curr_page = page
|
|
|
|
self:addOriginToLocationStack()
|
|
|
|
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
|
|
|
|
self:update()
|
|
|
|
end
|
|
|
|
|
2020-06-01 05:13:58 +00:00
|
|
|
function SkimToWidget:goToByEvent(event_name)
|
2023-09-15 04:24:31 +00:00
|
|
|
self:addOriginToLocationStack()
|
|
|
|
self.ui:handleEvent(Event:new(event_name, false))
|
|
|
|
-- add_current_location_to_stack=false, as we handled it here
|
|
|
|
self.curr_page = self.ui:getCurrentPage()
|
|
|
|
self:update()
|
2020-06-01 05:13:58 +00:00
|
|
|
end
|
|
|
|
|
2021-01-18 10:59:04 +00:00
|
|
|
function SkimToWidget:onFirstRowKeyPress(percent)
|
|
|
|
local page = Math.round(percent * self.page_count)
|
|
|
|
self:addOriginToLocationStack()
|
|
|
|
self.ui:handleEvent(Event:new("GotoPage", page ))
|
|
|
|
self.curr_page = page
|
|
|
|
self:update()
|
|
|
|
end
|
|
|
|
|
2016-12-29 07:27:48 +00:00
|
|
|
function SkimToWidget:onTapProgress(arg, ges_ev)
|
2018-01-29 20:27:24 +00:00
|
|
|
if ges_ev.pos:intersectWith(self.progress_bar.dimen) then
|
2019-12-06 21:55:39 +00:00
|
|
|
local perc = self.progress_bar:getPercentageFromPosition(ges_ev.pos)
|
|
|
|
if not perc then
|
|
|
|
return true
|
|
|
|
end
|
2018-01-29 20:27:24 +00:00
|
|
|
local page = Math.round(perc * self.page_count)
|
2018-08-15 13:22:55 +00:00
|
|
|
self:addOriginToLocationStack()
|
2016-12-29 07:27:48 +00:00
|
|
|
self.ui:handleEvent(Event:new("GotoPage", page ))
|
|
|
|
self.curr_page = page
|
|
|
|
self:update()
|
2018-01-29 20:27:24 +00:00
|
|
|
elseif not ges_ev.pos:intersectWith(self.skimto_frame.dimen) then
|
|
|
|
-- close if tap outside
|
2016-12-29 07:27:48 +00:00
|
|
|
self:onClose()
|
|
|
|
end
|
2018-01-29 20:27:24 +00:00
|
|
|
-- otherwise, do nothing (it's easy missing taping a button)
|
2016-12-29 07:27:48 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SkimToWidget:onClose()
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return SkimToWidget
|