separate abstract interface EventListener from Widget

The rationale is that some non-widget modules like ReaderKoptListener should be able
to handle events.
pull/2/merge
chrox 11 years ago
parent d304408ead
commit 74f76e98cc

@ -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
]]

Loading…
Cancel
Save