From ccb2134c2f252365de36d06b764b892246215a40 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Tue, 15 Oct 2024 04:06:24 +0200 Subject: [PATCH] Handle child events in reverse order --- gfx/prop/children.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gfx/prop/children.lua b/gfx/prop/children.lua index 17056ae..cdd207f 100644 --- a/gfx/prop/children.lua +++ b/gfx/prop/children.lua @@ -10,6 +10,16 @@ function Children:with(elementType) return ipairs(self:_children()) end + function elementType:_iterateChildrenReversed() + local children = self:_children() + return function(tbl, idx) + if idx < 1 then + return nil, nil + end + return idx - 1, tbl[idx] + end, children, #children + end + function elementType:_children() return propSelf:getState(self) end @@ -114,7 +124,7 @@ function Children:with(elementType) end function elementType:findChildById(id) - for _,child in self:_iterateChildren() do + for _,child in self:_iterateChildrenReversed() do local result = child:findById(id) if result then return result @@ -132,13 +142,13 @@ function Children:with(elementType) return false end - for _,child in self:_iterateChildren() do + for _,child in self:_iterateChildrenReversed() do if child:handleEvent(evtLocalCoords) then return true end end else - for _,child in self:_iterateChildren() do + for _,child in self:_iterateChildrenReversed() do if child:handleEvent(evtLocalCoords) then return true end