2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2020-12-19 11:18:30 +00:00
|
|
|
local IconWidget = require("ui/widget/iconwidget")
|
2017-08-03 18:06:30 +00:00
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
2021-02-20 18:25:06 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
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 WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2019-04-07 17:00:15 +00:00
|
|
|
local Screen = Device.screen
|
2013-02-24 11:49:23 +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 ReaderDogear = WidgetContainer:extend{}
|
2013-02-24 11:49:23 +00:00
|
|
|
|
|
|
|
function ReaderDogear:init()
|
2018-07-19 06:18:55 +00:00
|
|
|
-- This image could be scaled for DPI (with scale_for_dpi=true, scale_factor=0.7),
|
|
|
|
-- but it's as good to scale it to a fraction (1/32) of the screen size.
|
|
|
|
-- For CreDocument, we should additionally take care of not exceeding margins
|
|
|
|
-- to not overwrite the book text.
|
|
|
|
-- For other documents, there is no easy way to know if valuable content
|
|
|
|
-- may be hidden by the icon (kopt's page_margin is quite obscure).
|
2022-10-10 20:21:27 +00:00
|
|
|
self.dogear_min_size = math.ceil(math.min(Screen:getWidth(), Screen:getHeight()) * (1/40))
|
|
|
|
self.dogear_max_size = math.ceil(math.min(Screen:getWidth(), Screen:getHeight()) * (1/32))
|
2018-07-19 06:18:55 +00:00
|
|
|
self.dogear_size = nil
|
2021-02-20 18:25:06 +00:00
|
|
|
self.dogear_y_offset = 0
|
|
|
|
self.top_pad = nil
|
2018-07-19 06:18:55 +00:00
|
|
|
self:setupDogear()
|
2016-03-08 06:42:46 +00:00
|
|
|
self:resetLayout()
|
|
|
|
end
|
|
|
|
|
2018-07-19 06:18:55 +00:00
|
|
|
function ReaderDogear:setupDogear(new_dogear_size)
|
|
|
|
if not new_dogear_size then
|
|
|
|
new_dogear_size = self.dogear_max_size
|
|
|
|
end
|
|
|
|
if new_dogear_size ~= self.dogear_size then
|
|
|
|
self.dogear_size = new_dogear_size
|
|
|
|
if self[1] then
|
|
|
|
self[1]:free()
|
|
|
|
end
|
2021-02-20 18:25:06 +00:00
|
|
|
self.top_pad = VerticalSpan:new{width = self.dogear_y_offset}
|
|
|
|
self.vgroup = VerticalGroup:new{
|
|
|
|
self.top_pad,
|
2020-12-19 11:18:30 +00:00
|
|
|
IconWidget:new{
|
2021-03-01 00:35:55 +00:00
|
|
|
icon = "dogear.alpha",
|
2019-12-06 21:55:39 +00:00
|
|
|
rotation_angle = BD.mirroredUILayout() and 90 or 0,
|
2018-07-19 06:18:55 +00:00
|
|
|
width = self.dogear_size,
|
|
|
|
height = self.dogear_size,
|
2021-03-01 00:35:55 +00:00
|
|
|
alpha = true, -- Keep the alpha layer intact
|
2018-07-19 06:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-20 18:25:06 +00:00
|
|
|
self[1] = RightContainer:new{
|
|
|
|
dimen = Geom:new{w = Screen:getWidth(), h = self.dogear_y_offset + self.dogear_size},
|
|
|
|
self.vgroup
|
|
|
|
}
|
2018-07-19 06:18:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDogear:onReadSettings(config)
|
2023-01-01 15:11:12 +00:00
|
|
|
if self.ui.rolling then
|
2018-07-19 06:18:55 +00:00
|
|
|
-- Adjust to CreDocument margins (as done in ReaderTypeset)
|
2021-03-06 21:44:18 +00:00
|
|
|
local h_margins = config:readSetting("copt_h_page_margins")
|
|
|
|
or G_reader_settings:readSetting("copt_h_page_margins")
|
2022-09-27 23:10:50 +00:00
|
|
|
or G_defaults:readSetting("DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM")
|
2021-03-06 21:44:18 +00:00
|
|
|
local t_margin = config:readSetting("copt_t_page_margin")
|
|
|
|
or G_reader_settings:readSetting("copt_t_page_margin")
|
2022-09-27 23:10:50 +00:00
|
|
|
or G_defaults:readSetting("DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE")
|
2021-03-06 21:44:18 +00:00
|
|
|
local b_margin = config:readSetting("copt_b_page_margin")
|
|
|
|
or G_reader_settings:readSetting("copt_b_page_margin")
|
2022-09-27 23:10:50 +00:00
|
|
|
or G_defaults:readSetting("DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE")
|
2019-05-01 00:09:01 +00:00
|
|
|
local margins = { h_margins[1], t_margin, h_margins[2], b_margin }
|
|
|
|
self:onSetPageMargins(margins)
|
2018-07-19 06:18:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDogear:onSetPageMargins(margins)
|
2023-01-01 15:11:12 +00:00
|
|
|
if not self.ui.rolling then
|
2018-07-19 06:18:55 +00:00
|
|
|
-- we may get called by readerfooter (when hiding the footer)
|
|
|
|
-- on pdf documents and get margins=nil
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local margin_top, margin_right = margins[2], margins[3]
|
|
|
|
-- As the icon is squared, we can take the max() instead of the min() of
|
|
|
|
-- top & right margins and be sure no text is hidden by the icon
|
|
|
|
-- (the provided margins are not scaled, so do as ReaderTypeset)
|
|
|
|
local margin = Screen:scaleBySize(math.max(margin_top, margin_right))
|
2021-03-01 00:35:55 +00:00
|
|
|
local new_dogear_size = math.min(self.dogear_max_size, math.max(self.dogear_min_size, margin))
|
2018-07-19 06:18:55 +00:00
|
|
|
self:setupDogear(new_dogear_size)
|
|
|
|
end
|
|
|
|
|
2021-02-20 18:25:06 +00:00
|
|
|
function ReaderDogear:updateDogearOffset()
|
2023-01-01 15:11:12 +00:00
|
|
|
if not self.ui.rolling then
|
2021-02-20 18:25:06 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
self.dogear_y_offset = 0
|
|
|
|
if self.view.view_mode == "page" then
|
|
|
|
self.dogear_y_offset = self.ui.document:getHeaderHeight()
|
|
|
|
end
|
|
|
|
-- Update components heights and positionnings
|
|
|
|
if self[1] then
|
|
|
|
self[1].dimen.h = self.dogear_y_offset + self.dogear_size
|
|
|
|
self.top_pad.width = self.dogear_y_offset
|
|
|
|
self.vgroup:resetLayout()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-01 15:11:12 +00:00
|
|
|
function ReaderDogear:onReaderReady()
|
|
|
|
self:updateDogearOffset()
|
|
|
|
end
|
|
|
|
|
2022-10-25 11:16:01 +00:00
|
|
|
function ReaderDogear:onDocumentRerendered()
|
2021-02-20 18:25:06 +00:00
|
|
|
-- Catching the top status bar toggling with :onSetStatusLine()
|
2022-10-25 11:16:01 +00:00
|
|
|
-- would be too early. But "DocumentRerendered" is sent after
|
|
|
|
-- it has been applied
|
2021-02-20 18:25:06 +00:00
|
|
|
self:updateDogearOffset()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDogear:onChangeViewMode()
|
|
|
|
-- No top status bar when switching between page and scroll mode
|
|
|
|
self:updateDogearOffset()
|
|
|
|
end
|
|
|
|
|
2016-03-08 06:42:46 +00:00
|
|
|
function ReaderDogear:resetLayout()
|
2016-03-12 08:59:15 +00:00
|
|
|
local new_screen_width = Screen:getWidth()
|
|
|
|
if new_screen_width == self._last_screen_width then return end
|
|
|
|
self._last_screen_width = new_screen_width
|
|
|
|
|
|
|
|
self[1].dimen.w = new_screen_width
|
2013-02-24 11:49:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDogear:onSetDogearVisibility(visible)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.dogear_visible = visible
|
|
|
|
return true
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderDogear
|