2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/frontend/ui/widget/widget.lua

51 lines
1.3 KiB
Lua
Raw Normal View History

2013-10-18 20:38:07 +00:00
local EventListener = require("ui/widget/eventlistener")
2013-03-12 17:18:53 +00:00
--[[
This is a generic Widget interface
widgets can be queried about their size and can be paint.
that's it for now. Probably we need something more elaborate
later.
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.
--]]
2013-10-18 20:38:07 +00:00
local Widget = EventListener:new()
2013-03-12 17:18:53 +00:00
2013-08-14 09:17:25 +00:00
--[[
Use this method to define a class that's inherited from current class.
It only setup the metabale (or prototype chain) and will not initiatie
a real instance, i.e. call self:init()
--]]
2016-02-15 09:33:48 +00:00
function Widget:extend(from_o)
local o = from_o or {}
2014-03-13 13:52:43 +00:00
setmetatable(o, self)
self.__index = self
return o
2013-08-14 09:17:25 +00:00
end
--[[
Use this method to initiatie a instance of a class, don't use it for class
definition.
--]]
function Widget:new(o)
2014-03-13 13:52:43 +00:00
o = self:extend(o)
-- Both o._init and o.init are called on object creation. But o._init is
-- used for base widget initialization (basic component used to build other
2014-03-13 13:52:43 +00:00
-- widgets). While o.init is for higher level widgets, for example Menu
-- Widget
if o._init then o:_init() end
if o.init then o:init() end
return o
2013-03-12 17:18:53 +00:00
end
function Widget:getSize()
2014-03-13 13:52:43 +00:00
return self.dimen
2013-03-12 17:18:53 +00:00
end
function Widget:paintTo(bb, x, y)
end
2013-10-18 20:38:07 +00:00
return Widget