From 18c0cee18fc6eca5e1397b54023179c09459df61 Mon Sep 17 00:00:00 2001 From: Cosmin Gorgovan Date: Sun, 1 May 2016 13:46:17 +0100 Subject: [PATCH] UIManager: add method for broadcasting an event to all widgets --- frontend/ui/uimanager.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 11520b30e..8b38bfa54 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -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]