generate drawing rules in the correct order

Diffs=
c37a28468 generate drawing rules in the correct order (#6275)

Co-authored-by: hernan <hernan@rive.app>
diff --git a/.rive_head b/.rive_head
index ed532e6..b263d1a 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-ee674a819b3e4af245cb5b33bc60bab2741079ce
+c37a28468472c8bd33beaa1b31bf190ecaa6ce06
diff --git a/src/artboard.cpp b/src/artboard.cpp
index efd8838..68f8641 100644
--- a/src/artboard.cpp
+++ b/src/artboard.cpp
@@ -215,31 +215,42 @@
 
     sortDependencies();
 
-    DrawTarget root;
-    // Build up the draw order. Look for draw targets and build
-    // their dependencies.
+    std::vector<DrawRules*> rulesList;
+    // Build the rules in the right order. We use the map componentDrawRules
+    // to make sure we traverse the objects in the right order from parent
+    // to child, and add the rules accordingly.
     for (auto object : m_Objects)
     {
         if (object == nullptr)
         {
             continue;
         }
-        if (object->is<DrawTarget>())
+        auto itr = componentDrawRules.find(object);
+        if (itr != componentDrawRules.end())
         {
-            DrawTarget* target = object->as<DrawTarget>();
+            rulesList.emplace_back(componentDrawRules[object]);
+        }
+    }
+    DrawTarget root;
+    // Build up the draw order. Look for draw targets and build
+    // their dependencies.
+    for (auto rules : rulesList)
+    {
+        for (auto child : rules->children())
+        {
+            auto target = child->as<DrawTarget>();
             root.addDependent(target);
-
             auto dependentRules = target->drawable()->flattenedDrawRules;
             if (dependentRules != nullptr)
             {
                 // Because we don't store targets on rules, we need
                 // to find the targets that belong to this rule
                 // here.
-                for (auto object2 : m_Objects)
+                for (auto object : m_Objects)
                 {
-                    if (object2 != nullptr && object2->is<DrawTarget>())
+                    if (object != nullptr && object->is<DrawTarget>())
                     {
-                        DrawTarget* dependentTarget = object2->as<DrawTarget>();
+                        DrawTarget* dependentTarget = object->as<DrawTarget>();
                         if (dependentTarget->parent() == dependentRules)
                         {
                             dependentTarget->addDependent(target);