mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
separate abstract interface EventListener from Widget
The rationale is that some non-widget modules like ReaderKoptListener should be able to handle events.
This commit is contained in:
@@ -7,6 +7,31 @@ require "ui/inputevent"
|
||||
require "ui/gesturedetector"
|
||||
require "ui/font"
|
||||
|
||||
--[[
|
||||
The EventListener is an interface that handles events
|
||||
|
||||
EventListeners have a rudimentary event handler/dispatcher that
|
||||
will call a method "onEventName" for an event with name
|
||||
"EventName"
|
||||
|
||||
]]
|
||||
EventListener = {}
|
||||
|
||||
function EventListener:new(o)
|
||||
local o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
if o.init then o:init() end
|
||||
return o
|
||||
end
|
||||
|
||||
function EventListener:handleEvent(event)
|
||||
if self[event.handler] then
|
||||
return self[event.handler](self, unpack(event.args))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
This is a generic Widget interface
|
||||
|
||||
@@ -18,7 +43,7 @@ if the table that was given to us as parameter has an "init"
|
||||
method, it will be called. use this to set _instance_ variables
|
||||
rather than class variables.
|
||||
]]
|
||||
Widget = {}
|
||||
Widget = EventListener:new()
|
||||
|
||||
function Widget:new(o)
|
||||
local o = o or {}
|
||||
@@ -40,19 +65,6 @@ end
|
||||
function Widget:paintTo(bb, x, y)
|
||||
end
|
||||
|
||||
--[[
|
||||
Widgets have a rudimentary event handler/dispatcher that
|
||||
will call a method "onEventName" for an event with name
|
||||
"EventName"
|
||||
|
||||
These methods
|
||||
]]
|
||||
function Widget:handleEvent(event)
|
||||
if self[event.handler] then
|
||||
return self[event.handler](self, unpack(event.args))
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
WidgetContainer is a container for another Widget
|
||||
]]
|
||||
|
||||
Reference in New Issue
Block a user