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:
@@ -40,7 +40,7 @@ local T = FFIUtil.template
|
||||
--[[--
|
||||
Widget that displays a shortcut icon for menu item.
|
||||
--]]
|
||||
local ItemShortCutIcon = WidgetContainer:new{
|
||||
local ItemShortCutIcon = WidgetContainer:extend{
|
||||
dimen = Geom:new{ w = Screen:scaleBySize(22), h = Screen:scaleBySize(22) },
|
||||
key = nil,
|
||||
bordersize = Size.border.default,
|
||||
@@ -88,7 +88,7 @@ end
|
||||
--[[
|
||||
Widget that displays an item for menu
|
||||
--]]
|
||||
local MenuItem = InputContainer:new{
|
||||
local MenuItem = InputContainer:extend{
|
||||
text = nil,
|
||||
bidi_wrap_func = nil,
|
||||
show_parent = nil,
|
||||
@@ -425,7 +425,6 @@ function MenuItem:init()
|
||||
end
|
||||
|
||||
local _dots_cached_info
|
||||
|
||||
function MenuItem:getDotsText(face)
|
||||
local screen_w = Screen:getWidth()
|
||||
if not _dots_cached_info or _dots_cached_info.screen_width ~= screen_w
|
||||
@@ -565,7 +564,7 @@ end
|
||||
--[[
|
||||
Widget that displays menu
|
||||
--]]
|
||||
local Menu = FocusManager:new{
|
||||
local Menu = FocusManager:extend{
|
||||
show_parent = nil,
|
||||
|
||||
title = "No Title",
|
||||
@@ -576,7 +575,7 @@ local Menu = FocusManager:new{
|
||||
header_padding = Size.padding.default,
|
||||
dimen = nil,
|
||||
item_table = nil, -- NOT mandatory (will be empty)
|
||||
item_shortcuts = {
|
||||
item_shortcuts = { -- const
|
||||
"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
|
||||
"A", "S", "D", "F", "G", "H", "J", "K", "L", "Del",
|
||||
"Z", "X", "C", "V", "B", "N", "M", ".", "Sym",
|
||||
@@ -643,7 +642,7 @@ function Menu:init()
|
||||
self.show_parent = self.show_parent or self
|
||||
self.item_table = self.item_table or {}
|
||||
self.item_table_stack = {}
|
||||
self.dimen = Geom:new{ w = self.width, h = self.height or Screen:getHeight() }
|
||||
self.dimen = Geom:new{ x = 0, y = 0, w = self.width, h = self.height or Screen:getHeight() }
|
||||
if self.dimen.h > Screen:getHeight() or self.dimen.h == nil then
|
||||
self.dimen.h = Screen:getHeight()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user