From efb9ec93e59d54ade68f3b00167dc4733d959897 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 10 Dec 2023 20:40:13 -0800 Subject: [PATCH] Fix element ordering --- src/apply_mutations.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/apply_mutations.rs b/src/apply_mutations.rs index 0118fca..3961e3d 100644 --- a/src/apply_mutations.rs +++ b/src/apply_mutations.rs @@ -34,13 +34,12 @@ pub fn apply_mutations( match edit { Mutation::AppendChildren { id, m } => { let mut parent = commands.entity(element_id_to_bevy_ui_entity[&id]); - let parent_existing_children_count = + let parent_existing_child_count = hierarchy.keys().filter(|(p, _)| *p == parent.id()).count(); - for i in 1..=m { - let child = stack.pop().unwrap(); + for (i, child) in stack.drain((stack.len() - m)..).enumerate() { parent.add_child(child); hierarchy.insert( - (parent.id(), (parent_existing_children_count + i) as u8), + (parent.id(), (parent_existing_child_count + i + 1) as u8), child, ); }