mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +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.
This commit is contained in:
@@ -13,8 +13,8 @@ local _ = require("gettext")
|
||||
-- additionally handles a location stack for each visited page or
|
||||
-- page view change (when scrolling in a same page)
|
||||
|
||||
local ReaderBack = EventListener:new{
|
||||
location_stack = {},
|
||||
local ReaderBack = EventListener:extend{
|
||||
location_stack = nil, -- array
|
||||
-- a limit not intended to be a practical limit but just a failsafe
|
||||
max_stack = 5000,
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ local DISPLAY_PREFIX = {
|
||||
bookmark = "\u{F097}\u{2002}", -- "empty bookmark"
|
||||
}
|
||||
|
||||
local ReaderBookmark = InputContainer:new{
|
||||
local ReaderBookmark = InputContainer:extend{
|
||||
bookmarks_items_per_page_default = 14,
|
||||
bookmarks = nil,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
local ConfigDialog = require("ui/widget/configdialog")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local Geom = require("ui/geometry")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local CreOptions = require("ui/data/creoptions")
|
||||
local KoptOptions = require("ui/data/koptoptions")
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderConfig = InputContainer:new{
|
||||
local ReaderConfig = InputContainer:extend{
|
||||
last_panel_index = 1,
|
||||
}
|
||||
|
||||
@@ -20,7 +19,6 @@ function ReaderConfig:init()
|
||||
end
|
||||
self.configurable:loadDefaults(self.options)
|
||||
|
||||
if not self.dimen then self.dimen = Geom:new{} end
|
||||
if Device:hasKeys() then
|
||||
self.key_events = {
|
||||
ShowConfigMenu = { {{"Press","AA"}}, doc = "show config dialog" },
|
||||
@@ -120,7 +118,6 @@ end
|
||||
|
||||
function ReaderConfig:onShowConfigMenu()
|
||||
self.config_dialog = ConfigDialog:new{
|
||||
dimen = self.dimen:copy(),
|
||||
document = self.document,
|
||||
ui = self.ui,
|
||||
configurable = self.configurable,
|
||||
|
||||
@@ -8,7 +8,7 @@ local logger = require("logger")
|
||||
local T = require("ffi/util").template
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderCoptListener = EventListener:new{}
|
||||
local ReaderCoptListener = EventListener:extend{}
|
||||
|
||||
local CRE_HEADER_DEFAULT_SIZE = 20
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local Event = require("ui/event")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local Geom = require("ui/geometry")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local Math = require("optmath")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local Device = require("device")
|
||||
local Screen = Device.screen
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderCropping = InputContainer:new{}
|
||||
local ReaderCropping = WidgetContainer:extend{}
|
||||
|
||||
function ReaderCropping:onPageCrop(mode)
|
||||
self.ui:handleEvent(Event:new("CloseConfigMenu"))
|
||||
@@ -171,7 +171,9 @@ function ReaderCropping:setZoomMode(mode)
|
||||
end
|
||||
|
||||
function ReaderCropping:onReadSettings(config)
|
||||
self.document.bbox = config:readSetting("bbox")
|
||||
if config:has("bbox") then
|
||||
self.document.bbox = config:readSetting("bbox")
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderCropping:onSaveSettings()
|
||||
|
||||
@@ -2,15 +2,15 @@ local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local powerd = Device:getPowerDevice()
|
||||
local _ = require("gettext")
|
||||
local C_ = _.pgettext
|
||||
local T = require("ffi/util").template
|
||||
|
||||
local ReaderDeviceStatus = InputContainer:new{
|
||||
local ReaderDeviceStatus = WidgetContainer:extend{
|
||||
battery_confirm_box = nil,
|
||||
memory_confirm_box = nil,
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ local DictQuickLookup = require("ui/widget/dictquicklookup")
|
||||
local Event = require("ui/event")
|
||||
local Geom = require("ui/geometry")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local JSON = require("json")
|
||||
local KeyValuePage = require("ui/widget/keyvaluepage")
|
||||
@@ -16,6 +15,7 @@ local NetworkMgr = require("ui/network/manager")
|
||||
local SortWidget = require("ui/widget/sortwidget")
|
||||
local Trapper = require("ui/trapper")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local ffiUtil = require("ffi/util")
|
||||
@@ -60,9 +60,9 @@ local function getIfosInDir(path)
|
||||
return ifos
|
||||
end
|
||||
|
||||
local ReaderDictionary = InputContainer:new{
|
||||
local ReaderDictionary = WidgetContainer:extend{
|
||||
data_dir = nil,
|
||||
dict_window_list = {},
|
||||
dict_window_list = nil, -- array
|
||||
lookup_msg = _("Searching dictionary for:\n%1"),
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ local function getDictionaryFixHtmlFunc(path)
|
||||
end
|
||||
|
||||
function ReaderDictionary:init()
|
||||
self.dict_window_list = {}
|
||||
self.disable_lookup_history = G_reader_settings:isTrue("disable_lookup_history")
|
||||
self.dicts_order = G_reader_settings:readSetting("dicts_order", {})
|
||||
self.dicts_disabled = G_reader_settings:readSetting("dicts_disabled", {})
|
||||
@@ -156,7 +157,7 @@ function ReaderDictionary:init()
|
||||
self:updateSdcvDictNamesOptions()
|
||||
|
||||
if not lookup_history then
|
||||
lookup_history = LuaData:open(DataStorage:getSettingsDir() .. "/lookup_history.lua", { name = "LookupHistory" })
|
||||
lookup_history = LuaData:open(DataStorage:getSettingsDir() .. "/lookup_history.lua", "LookupHistory")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ local BD = require("ui/bidi")
|
||||
local Device = require("device")
|
||||
local Geom = require("ui/geometry")
|
||||
local IconWidget = require("ui/widget/iconwidget")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local RightContainer = require("ui/widget/container/rightcontainer")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local Screen = Device.screen
|
||||
|
||||
local ReaderDogear = InputContainer:new{}
|
||||
local ReaderDogear = WidgetContainer:extend{}
|
||||
|
||||
function ReaderDogear:init()
|
||||
-- This image could be scaled for DPI (with scale_for_dpi=true, scale_factor=0.7),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
local Geom = require("ui/geometry")
|
||||
local IconWidget = require("ui/widget/iconwidget")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local Screen = require("device").screen
|
||||
|
||||
local ReaderFlipping = InputContainer:new{
|
||||
local ReaderFlipping = WidgetContainer:extend{
|
||||
orig_reflow_mode = 0,
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ local _ = require("gettext")
|
||||
local C_ = _.pgettext
|
||||
local optionsutil = require("ui/data/optionsutil")
|
||||
|
||||
local ReaderFont = InputContainer:new{
|
||||
local ReaderFont = InputContainer:extend{
|
||||
font_face = nil,
|
||||
font_size = nil,
|
||||
line_space_percent = nil,
|
||||
|
||||
@@ -444,7 +444,7 @@ local ReaderFooter = WidgetContainer:extend{
|
||||
height = Screen:scaleBySize(G_defaults:readSetting("DMINIBAR_CONTAINER_HEIGHT")),
|
||||
horizontal_margin = Size.span.horizontal_default,
|
||||
bottom_padding = Size.padding.tiny,
|
||||
settings = {},
|
||||
settings = nil, -- table
|
||||
-- added to expose them to unit tests
|
||||
textGeneratorMap = footerTextGeneratorMap,
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
local Event = require("ui/event")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local SkimToWidget = require("ui/widget/skimtowidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local _ = require("gettext")
|
||||
local T = require("ffi/util").template
|
||||
|
||||
local ReaderGoto = InputContainer:new{
|
||||
}
|
||||
local ReaderGoto = WidgetContainer:extend{}
|
||||
|
||||
function ReaderGoto:init()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
|
||||
@@ -20,8 +20,7 @@ local C_ = _.pgettext
|
||||
local T = require("ffi/util").template
|
||||
local Screen = Device.screen
|
||||
|
||||
local ReaderHighlight = InputContainer:new{
|
||||
}
|
||||
local ReaderHighlight = InputContainer:extend{}
|
||||
|
||||
local function inside_box(pos, box)
|
||||
if pos then
|
||||
|
||||
@@ -2,10 +2,14 @@ local EventListener = require("ui/widget/eventlistener")
|
||||
|
||||
local DHINTCOUNT = G_defaults:readSetting("DHINTCOUNT")
|
||||
|
||||
local ReaderHinting = EventListener:new{
|
||||
hinting_states = {}
|
||||
local ReaderHinting = EventListener:extend{
|
||||
hinting_states = nil, -- array
|
||||
}
|
||||
|
||||
function ReaderHinting:init()
|
||||
self.hinting_states = {}
|
||||
end
|
||||
|
||||
function ReaderHinting:onHintPage()
|
||||
if not self.view.hinting then return true end
|
||||
for i=1, DHINTCOUNT do
|
||||
|
||||
@@ -4,7 +4,7 @@ local ReaderZooming = require("apps/reader/modules/readerzooming")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local util = require("util")
|
||||
|
||||
local ReaderKoptListener = EventListener:new{}
|
||||
local ReaderKoptListener = EventListener:extend{}
|
||||
|
||||
function ReaderKoptListener:setZoomMode(zoom_mode)
|
||||
if self.document.configurable.text_wrap == 1 then
|
||||
|
||||
@@ -21,8 +21,8 @@ local _ = require("gettext")
|
||||
local Screen = Device.screen
|
||||
local T = ffiutil.template
|
||||
|
||||
local ReaderLink = InputContainer:new{
|
||||
location_stack = {}
|
||||
local ReaderLink = InputContainer:extend{
|
||||
location_stack = nil, -- table, per-instance
|
||||
}
|
||||
|
||||
function ReaderLink:init()
|
||||
@@ -154,7 +154,7 @@ function ReaderLink:addToMainMenu(menu_items)
|
||||
-- insert table to main reader menu
|
||||
menu_items.go_to_previous_location = {
|
||||
text = _("Go back to previous location"),
|
||||
enabled_func = function() return #self.location_stack > 0 end,
|
||||
enabled_func = function() return self.location_stack and #self.location_stack > 0 end,
|
||||
callback = function() self:onGoBackLink() end,
|
||||
hold_callback = function(touchmenu_instance)
|
||||
UIManager:show(ConfirmBox:new{
|
||||
|
||||
@@ -13,10 +13,10 @@ local Screen = Device.screen
|
||||
local _ = require("gettext")
|
||||
local T = require("ffi/util").template
|
||||
|
||||
local ReaderMenu = InputContainer:new{
|
||||
local ReaderMenu = InputContainer:extend{
|
||||
tab_item_table = nil,
|
||||
menu_items = {},
|
||||
registered_widgets = {},
|
||||
menu_items = nil, -- table, mandatory
|
||||
registered_widgets = nil, -- array
|
||||
}
|
||||
|
||||
function ReaderMenu:init()
|
||||
|
||||
@@ -6,18 +6,18 @@ local Font = require("ui/font")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local Geom = require("ui/geometry")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
||||
local OverlapGroup = require("ui/widget/overlapgroup")
|
||||
local TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local Screen = Device.screen
|
||||
local T = require("ffi/util").template
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderPageMap = InputContainer:new{
|
||||
local ReaderPageMap = WidgetContainer:extend{
|
||||
label_font_face = "ffont",
|
||||
label_default_font_size = 14,
|
||||
-- Black so it's readable (and non-gray-flashing on GloHD)
|
||||
|
||||
@@ -27,7 +27,7 @@ local function copyPageState(page_state)
|
||||
end
|
||||
|
||||
|
||||
local ReaderPaging = InputContainer:new{
|
||||
local ReaderPaging = InputContainer:extend{
|
||||
pan_rate = 30, -- default 30 ops, will be adjusted in readerui
|
||||
current_page = 0,
|
||||
number_of_pages = 0,
|
||||
@@ -37,7 +37,7 @@ local ReaderPaging = InputContainer:new{
|
||||
|
||||
page_flipping_mode = false,
|
||||
bookmark_flipping_mode = false,
|
||||
flip_steps = {0,1,2,5,10,20,50,100},
|
||||
flip_steps = {0, 1, 2, 5, 10, 20, 50, 100},
|
||||
}
|
||||
|
||||
function ReaderPaging:init()
|
||||
|
||||
@@ -2,7 +2,7 @@ local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local Device = require("device")
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderPanning = InputContainer:new{
|
||||
local ReaderPanning = InputContainer:extend{
|
||||
-- defaults
|
||||
panning_steps = {
|
||||
normal = 50,
|
||||
|
||||
@@ -39,12 +39,12 @@ local band = bit.band
|
||||
it in explicit page turning. And use that xpointer for non-page-turning
|
||||
rendering.
|
||||
--]]
|
||||
local ReaderRolling = InputContainer:new{
|
||||
local ReaderRolling = InputContainer:extend{
|
||||
pan_rate = 30, -- default 30 ops, will be adjusted in readerui
|
||||
rendering_hash = 0,
|
||||
current_pos = 0,
|
||||
-- only used for page view mode
|
||||
current_page= nil,
|
||||
current_page = nil,
|
||||
xpointer = nil,
|
||||
panning_steps = ReaderPanning.panning_steps,
|
||||
cre_top_bar_enabled = false,
|
||||
|
||||
@@ -3,8 +3,8 @@ local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderRotation = InputContainer:new{
|
||||
current_rotation = 0
|
||||
local ReaderRotation = InputContainer:extend{
|
||||
current_rotation = 0,
|
||||
}
|
||||
|
||||
function ReaderRotation:init()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local logger = require("logger")
|
||||
local time = require("ui/time")
|
||||
local _ = require("gettext")
|
||||
@@ -16,7 +16,7 @@ local SCROLL_METHOD_CLASSIC = "classic"
|
||||
local SCROLL_METHOD_TURBO = "turbo"
|
||||
local SCROLL_METHOD_ON_RELEASE = "on_release"
|
||||
|
||||
local ReaderScrolling = InputContainer:new{
|
||||
local ReaderScrolling = WidgetContainer:extend{
|
||||
-- Available scrolling methods (make them available to other reader modules)
|
||||
SCROLL_METHOD_CLASSIC = SCROLL_METHOD_CLASSIC,
|
||||
SCROLL_METHOD_TURBO = SCROLL_METHOD_TURBO,
|
||||
@@ -221,9 +221,6 @@ function ReaderScrolling:applyScrollSettings()
|
||||
end
|
||||
|
||||
function ReaderScrolling:setupTouchZones()
|
||||
self.ges_events = {}
|
||||
self.onGesture = nil
|
||||
|
||||
local zones = {
|
||||
{
|
||||
id = "inertial_scrolling_touch",
|
||||
|
||||
@@ -3,10 +3,10 @@ local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local CheckButton = require("ui/widget/checkbutton")
|
||||
local Device = require("device")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local Notification = require("ui/widget/notification")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
local Screen = Device.screen
|
||||
@@ -14,7 +14,7 @@ local T = require("ffi/util").template
|
||||
|
||||
local DGENERIC_ICON_SIZE = G_defaults:readSetting("DGENERIC_ICON_SIZE")
|
||||
|
||||
local ReaderSearch = InputContainer:new{
|
||||
local ReaderSearch = WidgetContainer:extend{
|
||||
direction = 0, -- 0 for search forward, 1 for search backward
|
||||
case_insensitive = true, -- default to case insensitive
|
||||
|
||||
|
||||
@@ -4,22 +4,16 @@ local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local util = require("util")
|
||||
local _ = require("gettext")
|
||||
local T = require("ffi/util").template
|
||||
|
||||
local ReaderStatus = InputContainer:new {
|
||||
local ReaderStatus = WidgetContainer:extend{
|
||||
document = nil,
|
||||
summary = {
|
||||
rating = 0,
|
||||
note = nil,
|
||||
status = "",
|
||||
modified = "",
|
||||
},
|
||||
enabled = true,
|
||||
total_pages = 0
|
||||
total_pages = 0,
|
||||
}
|
||||
|
||||
function ReaderStatus:init()
|
||||
|
||||
@@ -19,6 +19,7 @@ local TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
@@ -27,7 +28,7 @@ local Screen = Device.screen
|
||||
local T = require("ffi/util").template
|
||||
|
||||
-- Simple widget for showing tweak info
|
||||
local TweakInfoWidget = InputContainer:new{
|
||||
local TweakInfoWidget = InputContainer:extend{
|
||||
tweak = nil,
|
||||
is_global_default = nil,
|
||||
toggle_global_default_callback = function() end,
|
||||
@@ -226,7 +227,7 @@ end
|
||||
|
||||
-- Reader component for managing tweaks. The aggregated css_text
|
||||
-- is actually requested from us and applied by ReaderTypeset
|
||||
local ReaderStyleTweak = InputContainer:new{
|
||||
local ReaderStyleTweak = WidgetContainer:extend{
|
||||
tweaks_by_id = nil,
|
||||
tweaks_table = nil, -- sub-menu items
|
||||
nb_enabled_tweaks = 0, -- for use by main menu item
|
||||
|
||||
@@ -2,11 +2,11 @@ local Blitbuffer = require("ffi/blitbuffer")
|
||||
local Cache = require("cache")
|
||||
local Device = require("device")
|
||||
local Geom = require("ui/geometry")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local Persist = require("persist")
|
||||
local RenderImage = require("ui/renderimage")
|
||||
local TileCacheItem = require("document/tilecacheitem")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local Screen = Device.screen
|
||||
local ffiutil = require("ffi/util")
|
||||
local logger = require("logger")
|
||||
@@ -18,7 +18,7 @@ local _ = require("gettext")
|
||||
-- It handles launching via the menu or Dispatcher/Gestures two fullscreen
|
||||
-- widgets related to showing pages and thumbnails that will make use of
|
||||
-- its services: BookMap and PageBrowser.
|
||||
local ReaderThumbnail = InputContainer:new{}
|
||||
local ReaderThumbnail = WidgetContainer:extend{}
|
||||
|
||||
function ReaderThumbnail:init()
|
||||
if not Device:isTouchDevice() then
|
||||
|
||||
@@ -20,15 +20,15 @@ local N_ = _.ngettext
|
||||
local Screen = Device.screen
|
||||
local T = require("ffi/util").template
|
||||
|
||||
local ReaderToc = InputContainer:new{
|
||||
local ReaderToc = InputContainer:extend{
|
||||
toc = nil,
|
||||
toc_depth = nil,
|
||||
ticks = nil,
|
||||
ticks_flattened = nil,
|
||||
ticks_flattened_filtered = nil,
|
||||
collapsed_toc = {},
|
||||
collapsed_toc = nil, -- table
|
||||
collapse_depth = 2,
|
||||
expanded_nodes = {},
|
||||
expanded_nodes = nil, -- table
|
||||
toc_menu_title = _("Table of contents"),
|
||||
alt_toc_menu_title = _("Table of contents *"),
|
||||
toc_items_per_page_default = 14,
|
||||
|
||||
@@ -2,10 +2,10 @@ local BD = require("ui/bidi")
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local Event = require("ui/event")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Math = require("optmath")
|
||||
local Notification = require("ui/widget/notification")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local optionsutil = require("ui/data/optionsutil")
|
||||
local _ = require("gettext")
|
||||
@@ -13,7 +13,7 @@ local C_ = _.pgettext
|
||||
local Screen = require("device").screen
|
||||
local T = require("ffi/util").template
|
||||
|
||||
local ReaderTypeset = InputContainer:new{
|
||||
local ReaderTypeset = WidgetContainer:extend{
|
||||
-- @translators This is style in the sense meant by CSS (cascading style sheets), relating to the layout and presentation of the document. See <https://en.wikipedia.org/wiki/CSS> for more information.
|
||||
css_menu_title = C_("CSS", "Style"),
|
||||
css = nil,
|
||||
|
||||
@@ -2,9 +2,9 @@ local BD = require("ui/bidi")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
local _ = require("gettext")
|
||||
@@ -12,7 +12,7 @@ local C_ = _.pgettext
|
||||
local T = require("ffi/util").template
|
||||
local Screen = Device.screen
|
||||
|
||||
local ReaderTypography = InputContainer:new{}
|
||||
local ReaderTypography = WidgetContainer:extend{}
|
||||
|
||||
-- This is used to migrate old hyph settings, and to show the currently
|
||||
-- used hyph dict language in the hyphenation menu.
|
||||
|
||||
@@ -16,7 +16,7 @@ local T = require("ffi/util").template
|
||||
-- and some `if NORM then` branches can be simplified.
|
||||
local NORM = false
|
||||
|
||||
local ReaderUserHyph = WidgetContainer:new{
|
||||
local ReaderUserHyph = WidgetContainer:extend{
|
||||
-- return values from setUserHyphenationDict (crengine's UserHyphDict::init())
|
||||
USER_DICT_RELOAD = 0,
|
||||
USER_DICT_NOCHANGE = 1,
|
||||
|
||||
@@ -28,28 +28,13 @@ local T = require("ffi/util").template
|
||||
|
||||
local ReaderView = OverlapGroup:extend{
|
||||
document = nil,
|
||||
view_modules = nil, -- array
|
||||
|
||||
-- single page state
|
||||
state = {
|
||||
page = nil,
|
||||
pos = 0,
|
||||
zoom = 1.0,
|
||||
rotation = 0,
|
||||
gamma = 1.0,
|
||||
offset = nil,
|
||||
bbox = nil,
|
||||
},
|
||||
state = nil, -- table
|
||||
outer_page_color = Blitbuffer.gray(G_defaults:readSetting("DOUTER_PAGE_COLOR") / 15),
|
||||
-- highlight with "lighten" or "underscore" or "strikeout" or "invert"
|
||||
highlight = {
|
||||
lighten_factor = G_reader_settings:readSetting("highlight_lighten_factor", 0.2),
|
||||
note_mark = G_reader_settings:readSetting("highlight_note_marker"),
|
||||
temp_drawer = "invert",
|
||||
temp = {},
|
||||
saved_drawer = "lighten",
|
||||
saved = {},
|
||||
indicator = nil, -- geom: non-touch highlight position indicator: {x = 50, y=50}
|
||||
},
|
||||
highlight = nil, -- table
|
||||
highlight_visible = true,
|
||||
note_mark_line_w = 3, -- side line thickness
|
||||
note_mark_sign = nil,
|
||||
@@ -58,12 +43,9 @@ local ReaderView = OverlapGroup:extend{
|
||||
-- PDF/DjVu continuous paging
|
||||
page_scroll = nil,
|
||||
page_bgcolor = Blitbuffer.gray(G_defaults:readSetting("DBACKGROUND_COLOR") / 15),
|
||||
page_states = {},
|
||||
page_states = nil, -- table
|
||||
-- properties of the gap drawn between each page in scroll mode:
|
||||
page_gap = {
|
||||
-- color (0 = white, 8 = gray, 15 = black)
|
||||
color = Blitbuffer.gray((G_reader_settings:readSetting("page_gap_color") or 8) / 15),
|
||||
},
|
||||
page_gap = nil, -- table
|
||||
-- DjVu page rendering mode (used in djvu.c:drawPage())
|
||||
render_mode = G_defaults:readSetting("DRENDER_MODE"), -- default to COLOR
|
||||
-- Crengine view mode
|
||||
@@ -91,10 +73,30 @@ local ReaderView = OverlapGroup:extend{
|
||||
|
||||
function ReaderView:init()
|
||||
self.view_modules = {}
|
||||
-- fix recalculate from close document pageno
|
||||
self.state.page = nil
|
||||
|
||||
-- Reset the various areas across documents
|
||||
self.state = {
|
||||
page = nil,
|
||||
pos = 0,
|
||||
zoom = 1.0,
|
||||
rotation = 0,
|
||||
gamma = 1.0,
|
||||
offset = nil,
|
||||
bbox = nil,
|
||||
}
|
||||
self.highlight = {
|
||||
lighten_factor = G_reader_settings:readSetting("highlight_lighten_factor", 0.2),
|
||||
note_mark = G_reader_settings:readSetting("highlight_note_marker"),
|
||||
temp_drawer = "invert",
|
||||
temp = {},
|
||||
saved_drawer = "lighten",
|
||||
saved = {},
|
||||
indicator = nil, -- geom: non-touch highlight position indicator: {x = 50, y=50}
|
||||
}
|
||||
self.page_states = {}
|
||||
self.page_gap = {
|
||||
-- color (0 = white, 8 = gray, 15 = black)
|
||||
color = Blitbuffer.gray((G_reader_settings:readSetting("page_gap_color") or 8) / 15),
|
||||
}
|
||||
self.visible_area = Geom:new{x = 0, y = 0, w = 0, h = 0}
|
||||
self.page_area = Geom:new{x = 0, y = 0, w = 0, h = 0}
|
||||
self.dim_area = Geom:new{x = 0, y = 0, w = 0, h = 0}
|
||||
@@ -103,6 +105,9 @@ function ReaderView:init()
|
||||
self.emitHintPageEvent = function()
|
||||
self.ui:handleEvent(Event:new("HintPage", self.hinting))
|
||||
end
|
||||
|
||||
-- We've subclassed OverlapGroup, go through its init, because it does some funky stuff with self.dimen...
|
||||
OverlapGroup.init(self)
|
||||
end
|
||||
|
||||
function ReaderView:addWidgets()
|
||||
@@ -1071,8 +1076,7 @@ function ReaderView:getRenderModeMenuTable()
|
||||
end
|
||||
|
||||
function ReaderView:onCloseDocument()
|
||||
self.hinting = false
|
||||
-- stop any in fly HintPage event
|
||||
-- stop any pending HintPage event
|
||||
UIManager:unschedule(self.emitHintPageEvent)
|
||||
end
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ function ReaderWikipedia:init()
|
||||
self.wiki_languages = {}
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
if not wikipedia_history then
|
||||
wikipedia_history = LuaData:open(DataStorage:getSettingsDir() .. "/wikipedia_history.lua", { name = "WikipediaHistory" })
|
||||
wikipedia_history = LuaData:open(DataStorage:getSettingsDir() .. "/wikipedia_history.lua", "WikipediaHistory")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ local Input = Device.input
|
||||
local Screen = Device.screen
|
||||
local T = require("ffi/util").template
|
||||
|
||||
local ReaderZooming = InputContainer:new{
|
||||
local ReaderZooming = InputContainer:extend{
|
||||
zoom = 1.0,
|
||||
available_zoom_modes = {
|
||||
available_zoom_modes = { -- const
|
||||
"page",
|
||||
"pagewidth",
|
||||
"pageheight",
|
||||
@@ -27,26 +27,26 @@ local ReaderZooming = InputContainer:new{
|
||||
"rows",
|
||||
"manual",
|
||||
},
|
||||
zoom_genus_to_mode = {
|
||||
zoom_genus_to_mode = { -- const
|
||||
[4] = "page",
|
||||
[3] = "content",
|
||||
[2] = "columns",
|
||||
[1] = "rows",
|
||||
[0] = "manual",
|
||||
},
|
||||
zoom_mode_to_genus = {
|
||||
zoom_mode_to_genus = { -- const
|
||||
page = 4,
|
||||
content = 3,
|
||||
columns = 2,
|
||||
rows = 1,
|
||||
manual = 0,
|
||||
},
|
||||
zoom_type_to_mode = {
|
||||
zoom_type_to_mode = { -- const
|
||||
[2] = "",
|
||||
[1] = "width",
|
||||
[0] = "height",
|
||||
},
|
||||
zoom_mode_to_type = {
|
||||
zoom_mode_to_type = { -- const
|
||||
[""] = 2,
|
||||
width = 1,
|
||||
height = 0,
|
||||
@@ -58,7 +58,7 @@ local ReaderZooming = InputContainer:new{
|
||||
-- with overlap of zoom_overlap_h % (horizontally)
|
||||
-- and zoom_overlap_v % (vertically).
|
||||
kopt_zoom_factor = 1.5,
|
||||
zoom_pan_settings = {
|
||||
zoom_pan_settings = { -- const
|
||||
"kopt_zoom_factor",
|
||||
"zoom_overlap_h",
|
||||
"zoom_overlap_v",
|
||||
@@ -71,7 +71,7 @@ local ReaderZooming = InputContainer:new{
|
||||
zoom_direction_vertical = nil, -- true for column mode
|
||||
current_page = 1,
|
||||
rotation = 0,
|
||||
paged_modes = {
|
||||
paged_modes = { -- const
|
||||
page = _("Zoom to fit page works best with page view."),
|
||||
pageheight = _("Zoom to fit page height works best with page view."),
|
||||
contentheight = _("Zoom to fit content height works best with page view."),
|
||||
|
||||
Reference in New Issue
Block a user