From 705ad20481b45cd8bd9b91353eb875931a84557b Mon Sep 17 00:00:00 2001
From: Gabriel Tofvesson <gabriel@tofvesson.se>
Date: Wed, 9 Oct 2024 23:12:09 +0200
Subject: [PATCH] Fix child iterator

---
 gfx/prop/children.lua | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/gfx/prop/children.lua b/gfx/prop/children.lua
index 8d73134..46088de 100644
--- a/gfx/prop/children.lua
+++ b/gfx/prop/children.lua
@@ -6,13 +6,14 @@ local Children = Prop:new{ defaultState = {}, uid = "CHILDREN" }
 function Children:with(elementType)
   local propSelf = self
   function elementType:_iterateChildren(opts)
-    local func, tbl, start = ipairs(propSelf:getState(self))
+    local tbl = propSelf:with(self)
+    local start, finish = ((opts and opts.from) or 1) - 1, (opts and opts.to) or #tbl
     return function(t, i)
-        if i == (opts and opts.to) then
-            return nil, nil
-        end
-        return func(t, i)
-    end, tbl, (opts and opts.from) or start
+      if i > finish then
+        return nil, nil
+      end
+      return i + 1, t[i + 1]
+    end, tbl, start
   end
 
   function elementType:childCount()
@@ -20,7 +21,7 @@ function Children:with(elementType)
   end
 
   function elementType:_childAt(index)
-    return propSelf:getState()[elementType:_validChildIndex(index)]
+    return propSelf:getState(self)[elementType:_validChildIndex(index)]
   end
 
   function elementType:_validChildIndex(from)