Fix element ordering

This commit is contained in:
JMS55 2023-12-10 20:40:13 -08:00
parent 52da5428fb
commit efb9ec93e5

View file

@ -34,13 +34,12 @@ pub fn apply_mutations(
match edit { match edit {
Mutation::AppendChildren { id, m } => { Mutation::AppendChildren { id, m } => {
let mut parent = commands.entity(element_id_to_bevy_ui_entity[&id]); 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(); hierarchy.keys().filter(|(p, _)| *p == parent.id()).count();
for i in 1..=m { for (i, child) in stack.drain((stack.len() - m)..).enumerate() {
let child = stack.pop().unwrap();
parent.add_child(child); parent.add_child(child);
hierarchy.insert( hierarchy.insert(
(parent.id(), (parent_existing_children_count + i) as u8), (parent.id(), (parent_existing_child_count + i + 1) as u8),
child, child,
); );
} }