2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00
koreader/frontend/ui/widget/widget.lua

76 lines
1.9 KiB
Lua
Raw Normal View History

2016-12-11 03:08:31 +00:00
--[[--
This is a generic Widget interface, which is the base class for all other widgets.
2013-03-12 17:18:53 +00:00
2016-12-11 03:08:31 +00:00
Widgets can be queried about their size and can be painted on screen.
2013-03-12 17:18:53 +00:00
that's it for now. Probably we need something more elaborate
later.
2016-12-11 03:08:31 +00:00
If the table that was given to us as parameter has an "init"
2013-03-12 17:18:53 +00:00
method, it will be called. use this to set _instance_ variables
rather than class variables.
2016-12-11 03:08:31 +00:00
]]
local EventListener = require("ui/widget/eventlistener")
2016-12-25 20:05:48 +00:00
--- Widget base class
-- @table Widget
2013-10-18 20:38:07 +00:00
local Widget = EventListener:new()
2013-03-12 17:18:53 +00:00
2016-12-11 03:08:31 +00:00
--[[--
Use this method to define a subclass widget class that's inherited from a
base class widget. It only setups the metabale (or prototype chain) and will
not initiate a real instance, i.e. call self:init().
@tparam Widget baseclass
@treturn Widget
]]
function Widget:extend(baseclass)
local o = baseclass 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
2016-12-11 03:08:31 +00:00
--[[--
2013-08-14 09:17:25 +00:00
Use this method to initiatie a instance of a class, don't use it for class
2016-12-11 03:08:31 +00:00
definition because it also calls self:init().
@tparam Widget o
@treturn Widget
]]
2013-08-14 09:17:25 +00:00
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
2016-12-11 03:08:31 +00:00
--[[
FIXME: enable this doc section when we verified all self.dimen is a Geom so we
can return self.dime:copy().
Return size of the widget.
@treturn ui.geometry.Geom
--]]
2013-03-12 17:18:53 +00:00
function Widget:getSize()
2014-03-13 13:52:43 +00:00
return self.dimen
2013-03-12 17:18:53 +00:00
end
2016-12-11 03:08:31 +00:00
--[[--
Paint widget to a BlitBuffer.
2016-12-25 20:05:48 +00:00
@tparam BlitBuffer bb BlitBuffer to paint to. If it's the screen BlitBuffer, then
2016-12-11 03:08:31 +00:00
widget will show up on screen refresh.
@int x x offset within the BlitBuffer
@int y y offset within the BlitBuffer
]]
2013-03-12 17:18:53 +00:00
function Widget:paintTo(bb, x, y)
end
2013-10-18 20:38:07 +00:00
return Widget