mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
UIManager: add method for broadcasting an event to all widgets
This commit is contained in:
@@ -347,7 +347,7 @@ function UIManager:quit()
|
||||
end
|
||||
end
|
||||
|
||||
-- transmit an event to registered widgets
|
||||
-- transmit an event to an active widget
|
||||
function UIManager:sendEvent(event)
|
||||
if #self._window_stack == 0 then return end
|
||||
-- top level widget has first access to the event
|
||||
@@ -368,6 +368,20 @@ function UIManager:sendEvent(event)
|
||||
end
|
||||
end
|
||||
|
||||
-- transmit an event to all registered widgets
|
||||
function UIManager:broadcastEvent(event)
|
||||
-- the widget's event handler might close widgets in which case
|
||||
-- a simple iterator like ipairs would skip over some entries
|
||||
local i = 1
|
||||
while (i <= #self._window_stack) do
|
||||
local prev_widget = self._window_stack[i].widget
|
||||
self._window_stack[i].widget:handleEvent(event)
|
||||
if (self._window_stack[i].widget == prev_widget) then
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UIManager:_checkTasks()
|
||||
local now = { util.gettime() }
|
||||
local now_us = now[1] * MILLION + now[2]
|
||||
|
||||
Reference in New Issue
Block a user