mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
InputContainer: Fall cleanup ;).
Get rid of the doc & seqtext fields, as they are not actually used (nor are they particularly useful, the event handler's name should be pretty self-explanatory). Also, tweak the key_events documentation to highlight the quirks of the API, especially as far as array nesting is involved... Random drive-by cleanup of the declarations of key_events & ges_events to re-use the existing instance object (now that we know they're sane ;p) for tables with a single member (less GC pressure).
This commit is contained in:
@@ -1,23 +1,33 @@
|
||||
--[[--
|
||||
An InputContainer is a WidgetContainer that handles user input events including multi touches
|
||||
and key presses.
|
||||
An InputContainer is a WidgetContainer that handles user input events including multi touches and key presses.
|
||||
|
||||
See @{InputContainer:registerTouchZones} for examples of how to listen for multi touch input.
|
||||
|
||||
This example illustrates how to listen for a key press input event:
|
||||
This example illustrates how to listen for a key press input event via the `key_events` hashmap:
|
||||
|
||||
PanBy20 = {
|
||||
{ "Shift", Input.group.Cursor },
|
||||
seqtext = "Shift+Cursor",
|
||||
doc = "pan by 20px",
|
||||
event = "Pan", args = 20, is_inactive = true,
|
||||
key_events = {
|
||||
PanBy20 = {
|
||||
{ "Shift", Input.group.Cursor }, -- Shift + (any member of) Cursor
|
||||
event = "Pan",
|
||||
args = 20,
|
||||
is_inactive = true,
|
||||
},
|
||||
PanNormal = {
|
||||
{ Input.group.Cursor }, -- Any member of Cursor (itself an array)
|
||||
event = "Pan",
|
||||
args = 10,
|
||||
},
|
||||
Exit = {
|
||||
{ "Alt", "F4" }, -- Alt + F4
|
||||
{ "Ctrl", "Q" }, -- Ctrl + Q
|
||||
},
|
||||
Home = {
|
||||
{ { "Home", "H" } }, -- Any of Home or H (note the extra nesting!)
|
||||
},
|
||||
End = {
|
||||
{ "End" }, -- NOTE: For a *single* key, we can forgo the nesting (c.f., match @ device/key).
|
||||
},
|
||||
},
|
||||
PanNormal = {
|
||||
{ Input.group.Cursor },
|
||||
seqtext = "Cursor",
|
||||
doc = "pan by 10 px", event = "Pan", args = 10,
|
||||
},
|
||||
Quit = { {"Home"} },
|
||||
|
||||
It is recommended to reference configurable sequences from another table
|
||||
and to store that table as a configuration setting.
|
||||
@@ -214,6 +224,7 @@ function InputContainer:onKeyPress(key)
|
||||
for name, seq in pairs(self.key_events) do
|
||||
if not seq.is_inactive then
|
||||
for _, oneseq in ipairs(seq) do
|
||||
-- NOTE: key is a device/key object, this isn't string.match!
|
||||
if key:match(oneseq) then
|
||||
local eventname = seq.event or name
|
||||
return self:handleEvent(Event:new(eventname, seq.args, key))
|
||||
|
||||
Reference in New Issue
Block a user