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