diff --git a/examples/demo.rs b/examples/demo.rs index 7181db0..445fb71 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -64,9 +64,9 @@ fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseState>) -> El onclick: move |_| { if Some(entity) == ***selected_entity { selected_entity.set(None); - return; + } else { + selected_entity.set(Some(entity)); } - selected_entity.set(Some(entity)); }, padding: "8", background_color: if Some(entity) == ***selected_entity { INDIGO_600 } else { NEUTRAL_800 }, @@ -95,12 +95,15 @@ fn EntityInspector<'a>(cx: Scope, selected_entity: &'a UseState>) let components = if let Some(selected_entity) = selected_entity.get() { let entity_ref = world.get_entity(*selected_entity).unwrap(); let archetype = entity_ref.archetype(); - let mut components = archetype.components().map(|component_id| { - let info = world.components().get_info(component_id).unwrap(); - let name = info.name(); + let mut components = archetype + .components() + .map(|component_id| { + let info = world.components().get_info(component_id).unwrap(); + let name = info.name(); - (name, component_id, info.type_id(), info.layout().size()) - }).collect::>(); + (name, component_id, info.type_id(), info.layout().size()) + }) + .collect::>(); components.sort_by(|(name_a, ..), (name_b, ..)| name_a.cmp(name_b)); components } else { @@ -110,24 +113,24 @@ fn EntityInspector<'a>(cx: Scope, selected_entity: &'a UseState>) render! { if selected_entity.is_none() { rsx! { - "Select an entity to view its components!!!" + "Select an entity to view its components" } } else { rsx! { div { flex_direction: "column", - for (name, component_id, type_id, size) in components { + for (name, _component_id, _type_id, _size) in components { div { padding: "8", background_color: NEUTRAL_800, - + div { "Component: {name}" } } } } - + } } } diff --git a/src/apply_mutations.rs b/src/apply_mutations.rs index ab72a59..ddfcdcf 100644 --- a/src/apply_mutations.rs +++ b/src/apply_mutations.rs @@ -86,26 +86,24 @@ pub fn apply_mutations( stack.push(entity); } Mutation::ReplaceWith { id, m } => { - let new_nodes = stack.split_off(stack.len() - m); let existing = element_id_to_bevy_ui_entity[&id]; + let existing_parent = world.entity(existing).get::().unwrap().get(); + let mut existing_parent = world.entity_mut(existing_parent); - // here we insert before the old entity that's going to be removed after - let parent = world.entity(existing).get::().unwrap().get(); - let mut parent = world.entity_mut(parent); - let index = parent + let existing_index = existing_parent .get::() .unwrap() .iter() .position(|child| *child == existing) .unwrap(); - parent.insert_children(index, &new_nodes); + existing_parent.insert_children(existing_index, &stack.split_off(stack.len() - m)); DespawnRecursive { entity: existing }.apply(world); // TODO: We're not removing child entities from the element maps if let Some(existing_element_id) = bevy_ui_entity_to_element_id.remove(&existing) { element_id_to_bevy_ui_entity.remove(&existing_element_id); - } - }, + } + } Mutation::ReplacePlaceholder { path, m } => { let mut existing = stack[stack.len() - m - 1]; for index in path { @@ -120,33 +118,28 @@ pub fn apply_mutations( .iter() .position(|child| *child == existing) .unwrap(); - let new = stack.drain((stack.len() - m)..).collect::>(); - existing_parent.insert_children(existing_index, &new); + existing_parent.insert_children(existing_index, &stack.split_off(stack.len() - m)); DespawnRecursive { entity: existing }.apply(world); // TODO: We're not removing child entities from the element maps if let Some(existing_element_id) = bevy_ui_entity_to_element_id.remove(&existing) { element_id_to_bevy_ui_entity.remove(&existing_element_id); - } + } } Mutation::InsertAfter { id, m } => { let entity = element_id_to_bevy_ui_entity[&id]; let parent = world.entity(entity).get::().unwrap().get(); let mut parent = world.entity_mut(parent); - let index = parent .get::() .unwrap() .iter() .position(|child| *child == entity) .unwrap(); - let new = stack.drain((stack.len() - m)..).collect::>(); - parent.insert_children(index + 1, &new); + parent.insert_children(index + 1, &stack.split_off(stack.len() - m)); } Mutation::InsertBefore { id, m } => { - let new_nodes = stack.split_off(stack.len() - m); let existing = element_id_to_bevy_ui_entity[&id]; - let parent = world.entity(existing).get::().unwrap().get(); let mut parent = world.entity_mut(parent); let index = parent @@ -155,7 +148,7 @@ pub fn apply_mutations( .iter() .position(|child| *child == existing) .unwrap(); - parent.insert_children(index, &new_nodes); + parent.insert_children(index, &stack.split_off(stack.len() - m)); } Mutation::SetAttribute { name, @@ -188,13 +181,10 @@ pub fn apply_mutations( } Mutation::RemoveEventListener { .. } => {} Mutation::Remove { id } => { - let existing = element_id_to_bevy_ui_entity[&id]; - DespawnRecursive { - entity: existing, - } - .apply(world); + let entity = element_id_to_bevy_ui_entity[&id]; + DespawnRecursive { entity }.apply(world); // TODO: We're not removing child entities from the element maps - if let Some(existing_element_id) = bevy_ui_entity_to_element_id.remove(&existing) { + if let Some(existing_element_id) = bevy_ui_entity_to_element_id.remove(&entity) { element_id_to_bevy_ui_entity.remove(&existing_element_id); } }