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:
@@ -91,10 +91,9 @@ local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local _ = require("gettext")
|
||||
local Screen = Device.screen
|
||||
|
||||
local input_field, input_description
|
||||
|
||||
local MultiInputDialog = InputDialog:extend{
|
||||
fields = {},
|
||||
fields = nil, -- array, mandatory
|
||||
input_fields = nil, -- array
|
||||
description_padding = Size.padding.default,
|
||||
description_margin = Size.margin.small,
|
||||
bottom_v_padding = Size.padding.default,
|
||||
@@ -108,19 +107,17 @@ function MultiInputDialog:init()
|
||||
self.title_bar,
|
||||
}
|
||||
|
||||
input_field = {}
|
||||
input_description = {}
|
||||
local k = 0
|
||||
self.input_field = {}
|
||||
local input_description = {}
|
||||
for i, field in ipairs(self.fields) do
|
||||
k = k + 1
|
||||
input_field[k] = InputText:new{
|
||||
self.input_field[i] = InputText:new{
|
||||
text = field.text or "",
|
||||
hint = field.hint or "",
|
||||
input_type = field.input_type or "string",
|
||||
text_type = field.text_type,
|
||||
face = self.input_face,
|
||||
width = math.floor(self.width * 0.9),
|
||||
focused = k == 1 and true or false,
|
||||
focused = i == 1 and true or false,
|
||||
scroll = false,
|
||||
parent = self,
|
||||
padding = field.padding or nil,
|
||||
@@ -133,9 +130,9 @@ function MultiInputDialog:init()
|
||||
auto_para_direction = field.auto_para_direction or self.auto_para_direction,
|
||||
alignment_strict = field.alignment_strict or self.alignment_strict,
|
||||
}
|
||||
table.insert(self.layout, #self.layout, {input_field[k]})
|
||||
table.insert(self.layout, #self.layout, {self.input_field[i]})
|
||||
if field.description then
|
||||
input_description[k] = FrameContainer:new{
|
||||
input_description[i] = FrameContainer:new{
|
||||
padding = self.description_padding,
|
||||
margin = self.description_margin,
|
||||
bordersize = 0,
|
||||
@@ -148,17 +145,17 @@ function MultiInputDialog:init()
|
||||
table.insert(VerticalGroupData, CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = self.title_bar:getSize().w,
|
||||
h = input_description[k]:getSize().h ,
|
||||
h = input_description[i]:getSize().h ,
|
||||
},
|
||||
input_description[k],
|
||||
input_description[i],
|
||||
})
|
||||
end
|
||||
table.insert(VerticalGroupData, CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = self.title_bar:getSize().w,
|
||||
h = input_field[k]:getSize().h,
|
||||
h = self.input_field[i]:getSize().h,
|
||||
},
|
||||
input_field[k],
|
||||
self.input_field[i],
|
||||
})
|
||||
end
|
||||
|
||||
@@ -188,7 +185,7 @@ function MultiInputDialog:init()
|
||||
VerticalGroupData,
|
||||
}
|
||||
|
||||
self._input_widget = input_field[1]
|
||||
self._input_widget = self.input_field[1]
|
||||
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
@@ -204,14 +201,20 @@ function MultiInputDialog:init()
|
||||
|
||||
end
|
||||
|
||||
--- Returns an array of our input field's *text* field.
|
||||
function MultiInputDialog:getFields()
|
||||
local fields = {}
|
||||
for i=1, #input_field do
|
||||
table.insert(fields, input_field[i].text)
|
||||
for i, field in ipairs(self.input_field) do
|
||||
table.insert(fields, field.text)
|
||||
end
|
||||
return fields
|
||||
end
|
||||
|
||||
--- BEWARE: Live ref to an internal component!
|
||||
function MultiInputDialog:getRawFields()
|
||||
return self.input_field
|
||||
end
|
||||
|
||||
function MultiInputDialog:onSwitchFocus(inputbox)
|
||||
-- unfocus current inputbox
|
||||
self._input_widget:unfocus()
|
||||
|
||||
Reference in New Issue
Block a user