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())
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