Handle child events in reverse order

This commit is contained in:
Gabriel Tofvesson 2024-10-15 04:06:24 +02:00
parent a0b995c288
commit ccb2134c2f

View File

@ -10,6 +10,16 @@ function Children:with(elementType)
return ipairs(self:_children()) return ipairs(self:_children())
end 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() function elementType:_children()
return propSelf:getState(self) return propSelf:getState(self)
end end
@ -114,7 +124,7 @@ function Children:with(elementType)
end end
function elementType:findChildById(id) function elementType:findChildById(id)
for _,child in self:_iterateChildren() do for _,child in self:_iterateChildrenReversed() do
local result = child:findById(id) local result = child:findById(id)
if result then if result then
return result return result
@ -132,13 +142,13 @@ function Children:with(elementType)
return false return false
end end
for _,child in self:_iterateChildren() do for _,child in self:_iterateChildrenReversed() do
if child:handleEvent(evtLocalCoords) then if child:handleEvent(evtLocalCoords) then
return true return true
end end
end end
else else
for _,child in self:_iterateChildren() do for _,child in self:_iterateChildrenReversed() do
if child:handleEvent(evtLocalCoords) then if child:handleEvent(evtLocalCoords) then
return true return true
end end