@@ -386,115 +386,68 @@ MoveDownRoot(std::vector<std::shared_ptr<mvAppItem>>& roots, mvUUID uuid)
386386static b8
387387AddRuntimeChild (mvAppItem* rootitem, mvUUID parent, mvUUID before, std::shared_ptr<mvAppItem> item)
388388{
389- if (before == 0 && parent == 0 )
390- return false ;
391-
392- for (auto & children : rootitem->childslots )
389+ // this is the container, add item to end.
390+ if (before == 0 )
393391 {
394- // this is the container, add item to end.
395- if (before == 0 )
392+ // checking if `rootitem` is the parent we're looking for
393+ if (rootitem-> uuid == parent )
396394 {
397-
398- if (rootitem->uuid == parent)
399- {
400- i32 targetSlot = DearPyGui::GetEntityTargetSlot (item->type );
401- item->info .location = (i32 )rootitem->childslots [targetSlot].size ();
402- rootitem->childslots [targetSlot].push_back (item);
403- DearPyGui::OnChildAdded (rootitem, item);
404- item->info .parentPtr = rootitem;
405- item->config .parent = rootitem->uuid ;
406- return true ;
407- }
408-
409- // check children
410- for (auto & childslot : rootitem->childslots )
411- {
412- for (auto & child : childslot)
413- {
414-
415- if (!child)
416- continue ;
417-
418- if (DearPyGui::GetEntityDesciptionFlags (child->type ) & MV_ITEM_DESC_CONTAINER
419- || DearPyGui::GetEntityDesciptionFlags (item->type ) & MV_ITEM_DESC_HANDLER)
420- {
421- // parent found
422- if (AddRuntimeChild (child.get (), parent, before, item))
423- return true ;
424- }
425- }
426- }
395+ i32 targetSlot = DearPyGui::GetEntityTargetSlot (item->type );
396+ item->info .location = (i32 )rootitem->childslots [targetSlot].size ();
397+ rootitem->childslots [targetSlot].push_back (item);
398+ item->info .parentPtr = rootitem;
399+ item->config .parent = rootitem->uuid ;
400+ DearPyGui::OnChildAdded (rootitem, item);
401+ return true ;
427402 }
428403
429- // this is the container, add item to beginning.
430- else
404+ }
405+ // this is the container, add item to beginning.
406+ else
407+ {
408+ for (auto & childslot : rootitem->childslots )
431409 {
432- bool beforeFound = false ;
433-
434- // check children
435- for (auto & child : children)
410+ for (auto it = childslot.begin (); it != childslot.end (); ++it)
411+ // for (auto& child : childslot)
436412 {
413+ auto child = *it;
437414 if (!child)
438415 continue ;
439416
440417 if (child->uuid == before)
441418 {
442- beforeFound = true ;
443- break ;
444- }
445- }
446-
447-
448- // after item is in this container
449- if (beforeFound)
450- {
451- item->info .parentPtr = rootitem;
452-
453- std::vector<std::shared_ptr<mvAppItem>> oldchildren = children;
454- children.clear ();
455-
456- int location = 0 ;
457- for (auto & child : oldchildren)
458- {
459- if (!child)
460- continue ;
461-
462- if (child->uuid == before)
463- {
464- children.push_back (item);
465- item->info .location = location;
466- DearPyGui::OnChildAdded (rootitem, item);
467- ++location;
468- }
469- children.push_back (child);
470- ++location;
471-
419+ childslot.insert (it, item);
420+ item->info .parentPtr = rootitem;
421+ item->config .parent = rootitem->uuid ;
422+ // TODO: this one can be optimized a lot (we only need to update
423+ // locations in the tail of the current slot, not in all 4 slots).
424+ UpdateChildLocations (rootitem->childslots , 4 );
425+ DearPyGui::OnChildAdded (rootitem, item);
426+ return true ;
472427 }
473-
474- // TODO: maybe remove this call since location gets updated inside the loop
475- UpdateChildLocations (rootitem->childslots , 4 );
476-
477- return true ;
478428 }
479429 }
430+ }
480431
481- // check children
482- for (auto & child : children)
432+ bool is_handler = (DearPyGui::GetEntityDesciptionFlags (item->type ) & MV_ITEM_DESC_HANDLER);
433+
434+ // check children
435+ for (auto & childslot : rootitem->childslots )
436+ {
437+ for (auto & child : childslot)
483438 {
439+
484440 if (!child)
485441 continue ;
486442
487- if (DearPyGui::GetEntityDesciptionFlags (child->type ) & MV_ITEM_DESC_CONTAINER
488- || DearPyGui::GetEntityDesciptionFlags (item->type ) & MV_ITEM_DESC_HANDLER)
443+ if (DearPyGui::GetEntityDesciptionFlags (child->type ) & MV_ITEM_DESC_CONTAINER || is_handler)
489444 {
490445 // parent found
491446 if (AddRuntimeChild (child.get (), parent, before, item))
492447 return true ;
493448 }
494449 }
495-
496- };
497-
450+ }
498451 return false ;
499452}
500453
@@ -623,6 +576,8 @@ AddItem(mvItemRegistry& registry, std::shared_ptr<mvAppItem> item)
623576static b8
624577AddRuntimeItem (mvItemRegistry& registry, mvUUID parent, mvUUID before, std::shared_ptr<mvAppItem> item)
625578{
579+ if (before == 0 && parent == 0 )
580+ return false ;
626581
627582 if (AddRuntimeChildRoot (registry.colormapRoots , parent, before, item)) return true ;
628583 else if (AddRuntimeChildRoot (registry.filedialogRoots , parent, before, item)) return true ;
0 commit comments