2021-12-01 11:37:18 +00:00
|
|
|
--[[--
|
|
|
|
Widget for taking multiple user inputs.
|
|
|
|
|
|
|
|
Example for input of two strings and a number:
|
|
|
|
|
|
|
|
local MultiInputDialog = require("ui/widget/multiinputdialog")
|
|
|
|
local @{ui.uimanager|UIManager} = require("ui/uimanager")
|
|
|
|
local @{gettext|_} = require("gettext")
|
|
|
|
|
|
|
|
local sample_input
|
|
|
|
sample_input = MultiInputDialog:new{
|
|
|
|
title = _("Title to show"),
|
|
|
|
fields = {
|
|
|
|
{
|
|
|
|
description = _("Describe this field"),
|
|
|
|
-- input_type = nil, -- default for text
|
|
|
|
text = _("First input"),
|
|
|
|
hint = _("Name"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "",
|
|
|
|
hint = _("Address"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description = _("Enter a number"),
|
|
|
|
input_type = "number",
|
|
|
|
text = 666,
|
|
|
|
hint = 123,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
id = "close",
|
2021-12-01 11:37:18 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:close(sample_input)
|
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Info"),
|
|
|
|
callback = function()
|
|
|
|
-- do something
|
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Use settings"),
|
|
|
|
callback = function(touchmenu_instance)
|
2022-10-06 15:11:47 +00:00
|
|
|
local fields = sample_input:getFields()
|
2021-12-01 11:37:18 +00:00
|
|
|
-- check for user input
|
|
|
|
if fields[1] ~= "" and fields[2] ~= ""
|
|
|
|
and fields[3] ~= 0 then
|
|
|
|
-- insert code here
|
|
|
|
UIManager:close(sample_input)
|
|
|
|
-- If we have a touch menu: Update menu entries,
|
|
|
|
-- when called from a menu
|
|
|
|
if touchmenu_instance then
|
|
|
|
touchmenu_instance:updateItems()
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- not all fields where entered
|
|
|
|
end
|
|
|
|
end
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(sample_input)
|
|
|
|
sample_input:onShowKeyboard()
|
|
|
|
|
|
|
|
|
|
|
|
It is strongly recommended to use a text describing the action to be
|
|
|
|
executed, as demonstrated in the example above. If the resulting phrase would be
|
|
|
|
longer than three words it should just read "OK".
|
|
|
|
--]]--
|
|
|
|
|
|
|
|
|
2017-09-14 20:31:25 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2014-08-25 16:00:11 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-09-14 20:31:25 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
2014-08-25 16:00:11 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local InputText = require("ui/widget/inputtext")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-09-14 20:31:25 +00:00
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
2014-08-25 16:00:11 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2017-09-14 20:31:25 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2017-10-08 15:53:25 +00:00
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2014-08-25 16:00:11 +00:00
|
|
|
local _ = require("gettext")
|
2017-09-14 20:31:25 +00:00
|
|
|
local Screen = Device.screen
|
2014-08-25 16:00:11 +00:00
|
|
|
|
|
|
|
local MultiInputDialog = InputDialog:extend{
|
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
|
|
|
fields = nil, -- array, mandatory
|
|
|
|
input_fields = nil, -- array
|
2017-09-13 14:56:20 +00:00
|
|
|
description_padding = Size.padding.default,
|
|
|
|
description_margin = Size.margin.small,
|
2022-01-20 10:36:35 +00:00
|
|
|
bottom_v_padding = Size.padding.default,
|
2014-08-25 16:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function MultiInputDialog:init()
|
|
|
|
-- init title and buttons in base class
|
|
|
|
InputDialog.init(self)
|
|
|
|
local VerticalGroupData = VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
self.title_bar,
|
|
|
|
}
|
|
|
|
|
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
|
|
|
self.input_field = {}
|
|
|
|
local input_description = {}
|
2014-09-05 13:05:20 +00:00
|
|
|
for i, field in ipairs(self.fields) do
|
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
|
|
|
self.input_field[i] = InputText:new{
|
2014-09-05 13:05:20 +00:00
|
|
|
text = field.text or "",
|
|
|
|
hint = field.hint or "",
|
2015-09-07 17:06:17 +00:00
|
|
|
input_type = field.input_type or "string",
|
2018-09-18 18:21:14 +00:00
|
|
|
text_type = field.text_type,
|
2014-08-25 16:00:11 +00:00
|
|
|
face = self.input_face,
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.floor(self.width * 0.9),
|
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
|
|
|
focused = i == 1 and true or false,
|
2014-08-25 16:00:11 +00:00
|
|
|
scroll = false,
|
|
|
|
parent = self,
|
2018-07-07 22:45:27 +00:00
|
|
|
padding = field.padding or nil,
|
|
|
|
margin = field.margin or nil,
|
2019-12-06 21:55:35 +00:00
|
|
|
-- Allow these to be specified per field if needed
|
|
|
|
alignment = field.alignment or self.alignment,
|
|
|
|
justified = field.justified or self.justified,
|
|
|
|
lang = field.lang or self.lang,
|
|
|
|
para_direction_rtl = field.para_direction_rtl or self.para_direction_rtl,
|
|
|
|
auto_para_direction = field.auto_para_direction or self.auto_para_direction,
|
|
|
|
alignment_strict = field.alignment_strict or self.alignment_strict,
|
2014-08-25 16:00:11 +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
|
|
|
table.insert(self.layout, #self.layout, {self.input_field[i]})
|
2017-09-14 20:31:25 +00:00
|
|
|
if field.description then
|
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
|
|
|
input_description[i] = FrameContainer:new{
|
2017-09-14 20:31:25 +00:00
|
|
|
padding = self.description_padding,
|
|
|
|
margin = self.description_margin,
|
|
|
|
bordersize = 0,
|
|
|
|
TextBoxWidget:new{
|
|
|
|
text = field.description,
|
|
|
|
face = Font:getFace("x_smallinfofont"),
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.floor(self.width * 0.9),
|
2017-09-14 20:31:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
table.insert(VerticalGroupData, CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
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
|
|
|
h = input_description[i]:getSize().h ,
|
2017-09-14 20:31:25 +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
|
|
|
input_description[i],
|
2017-09-14 20:31:25 +00:00
|
|
|
})
|
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
table.insert(VerticalGroupData, CenterContainer:new{
|
2014-08-25 16:00:11 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
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
|
|
|
h = self.input_field[i]:getSize().h,
|
2014-08-25 16:00:11 +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
|
|
|
self.input_field[i],
|
2014-08-25 16:00:11 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-10-08 15:53:25 +00:00
|
|
|
-- Add same vertical space after than before InputText
|
|
|
|
table.insert(VerticalGroupData,CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.description_padding + self.description_margin,
|
|
|
|
},
|
|
|
|
VerticalSpan:new{ width = self.description_padding + self.description_margin },
|
|
|
|
})
|
2014-08-25 16:00:11 +00:00
|
|
|
-- buttons
|
|
|
|
table.insert(VerticalGroupData,CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.button_table:getSize().h,
|
|
|
|
},
|
|
|
|
self.button_table,
|
|
|
|
})
|
|
|
|
|
|
|
|
self.dialog_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
|
|
|
bordersize = Size.border.window,
|
2014-08-25 16:00:11 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-08-25 16:00:11 +00:00
|
|
|
VerticalGroupData,
|
|
|
|
}
|
|
|
|
|
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
|
|
|
self._input_widget = self.input_field[1]
|
2014-08-25 16:00:11 +00:00
|
|
|
|
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = Screen:getWidth(),
|
2021-10-01 18:33:39 +00:00
|
|
|
h = Screen:getHeight() - self._input_widget:getKeyboardDimen().h,
|
2014-08-25 16:00:11 +00:00
|
|
|
},
|
2021-10-01 18:33:39 +00:00
|
|
|
ignore_if_over = "height",
|
2014-08-25 16:00:11 +00:00
|
|
|
self.dialog_frame,
|
|
|
|
}
|
2022-02-02 19:31:24 +00:00
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
|
|
|
|
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
|
|
|
--- Returns an array of our input field's *text* field.
|
2014-09-05 13:05:20 +00:00
|
|
|
function MultiInputDialog:getFields()
|
|
|
|
local fields = {}
|
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
|
|
|
for i, field in ipairs(self.input_field) do
|
2022-10-06 15:11:47 +00:00
|
|
|
table.insert(fields, field:getText())
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
2014-09-05 13:05:20 +00:00
|
|
|
return fields
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
|
|
|
|
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
|
|
|
--- BEWARE: Live ref to an internal component!
|
|
|
|
function MultiInputDialog:getRawFields()
|
|
|
|
return self.input_field
|
|
|
|
end
|
|
|
|
|
2014-08-25 16:00:11 +00:00
|
|
|
function MultiInputDialog:onSwitchFocus(inputbox)
|
|
|
|
-- unfocus current inputbox
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget:unfocus()
|
2023-09-01 20:51:41 +00:00
|
|
|
-- and close its existing keyboard (via InputDialog's thin wrapper around _input_widget's own method)
|
|
|
|
self:onCloseKeyboard()
|
|
|
|
|
2018-07-07 22:45:27 +00:00
|
|
|
UIManager:setDirty(nil, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
2014-08-25 16:00:11 +00:00
|
|
|
|
|
|
|
-- focus new inputbox
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget = inputbox
|
|
|
|
self._input_widget:focus()
|
2023-09-01 20:51:41 +00:00
|
|
|
|
|
|
|
-- Make sure we have a (new) visible keyboard
|
|
|
|
self:onShowKeyboard()
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return MultiInputDialog
|
|
|
|
|