doc: Event and WidgetContainer

pull/2416/head
Qingping Hou 8 years ago
parent 329fd55302
commit 11f55d2aff

@ -1,14 +1,30 @@
--[[ --[[--
Events are messages that are passed through the widget tree Events are messages that are passed through the widget tree
Events need a "name" attribute as minimal data. Events need a "name" attribute as minimal data.
In order to see how event propagation works and how to make In order to see how event propagation works and how to make
widgets event-aware see the implementation in WidgetContainer widgets event-aware see the implementation in @{ui.widget.container.widgetcontainer}.
below. ]]
--[[--
@field handler name for the handler method
@field args array of arguments for the event
@table Event
]] ]]
local Event = {} local Event = {}
--[[--
Create a new event.
@string name
@tparam[opt] ... arguments for the event
@treturn Event
@usage
local Event = require("ui/event")
Event:new("GotoPage", 1)
]]
function Event:new(name, ...) function Event:new(name, ...)
local o = { local o = {
handler = "on"..name, handler = "on"..name,

@ -1,3 +1,9 @@
--[[--
WidgetContainer is a container for another Widget. Base class for all the widget containers.
It handles event propagation and paiting (with different alignments) for its children.
]]
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Widget = require("ui/widget/widget") local Widget = require("ui/widget/widget")
@ -5,9 +11,6 @@ if require("device"):isAndroid() then
require("jit").off(true, true) require("jit").off(true, true)
end end
--[[
WidgetContainer is a container for another Widget
--]]
local WidgetContainer = Widget:new() local WidgetContainer = Widget:new()
function WidgetContainer:init() function WidgetContainer:init()
@ -37,9 +40,9 @@ function WidgetContainer:getSize()
end end
end end
--[[ --[[--
delete all child widgets Delete all child widgets
--]] ]]
function WidgetContainer:clear() function WidgetContainer:clear()
while table.remove(self) do end while table.remove(self) do end
end end
@ -80,9 +83,15 @@ function WidgetContainer:propagateEvent(event)
return false return false
end end
--[[ --[[--
Containers will pass events to children or react on them themselves WidgetContainer will pass event to its children by calling their handleEvent
--]] methods. If no child responded to the event (by returning true), it will call its own
handleEvent method.
@tparam ui.event.Event event
@treturn bool true if event is consumed, othewise false. A consumed event will
not be sent to other widgets.
]]
function WidgetContainer:handleEvent(event) function WidgetContainer:handleEvent(event)
if not self:propagateEvent(event) then if not self:propagateEvent(event) then
-- call our own standard event handler -- call our own standard event handler

Loading…
Cancel
Save