Stylistic cleanup

This commit is contained in:
JMS55 2023-12-17 12:19:08 -08:00
parent 0ccb49e5e7
commit 9d5b0408c0
2 changed files with 27 additions and 34 deletions

View file

@ -64,9 +64,9 @@ fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseState<Option<Entity>>) -> El
onclick: move |_| { onclick: move |_| {
if Some(entity) == ***selected_entity { if Some(entity) == ***selected_entity {
selected_entity.set(None); selected_entity.set(None);
return; } else {
selected_entity.set(Some(entity));
} }
selected_entity.set(Some(entity));
}, },
padding: "8", padding: "8",
background_color: if Some(entity) == ***selected_entity { INDIGO_600 } else { NEUTRAL_800 }, 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<Option<Entity>>)
let components = if let Some(selected_entity) = selected_entity.get() { let components = if let Some(selected_entity) = selected_entity.get() {
let entity_ref = world.get_entity(*selected_entity).unwrap(); let entity_ref = world.get_entity(*selected_entity).unwrap();
let archetype = entity_ref.archetype(); let archetype = entity_ref.archetype();
let mut components = archetype.components().map(|component_id| { let mut components = archetype
let info = world.components().get_info(component_id).unwrap(); .components()
let name = info.name(); .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()) (name, component_id, info.type_id(), info.layout().size())
}).collect::<Vec<_>>(); })
.collect::<Vec<_>>();
components.sort_by(|(name_a, ..), (name_b, ..)| name_a.cmp(name_b)); components.sort_by(|(name_a, ..), (name_b, ..)| name_a.cmp(name_b));
components components
} else { } else {
@ -110,13 +113,13 @@ fn EntityInspector<'a>(cx: Scope, selected_entity: &'a UseState<Option<Entity>>)
render! { render! {
if selected_entity.is_none() { if selected_entity.is_none() {
rsx! { rsx! {
"Select an entity to view its components!!!" "Select an entity to view its components"
} }
} else { } else {
rsx! { rsx! {
div { div {
flex_direction: "column", flex_direction: "column",
for (name, component_id, type_id, size) in components { for (name, _component_id, _type_id, _size) in components {
div { div {
padding: "8", padding: "8",
background_color: NEUTRAL_800, background_color: NEUTRAL_800,

View file

@ -86,26 +86,24 @@ pub fn apply_mutations(
stack.push(entity); stack.push(entity);
} }
Mutation::ReplaceWith { id, m } => { Mutation::ReplaceWith { id, m } => {
let new_nodes = stack.split_off(stack.len() - m);
let existing = element_id_to_bevy_ui_entity[&id]; let existing = element_id_to_bevy_ui_entity[&id];
let existing_parent = world.entity(existing).get::<Parent>().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 existing_index = existing_parent
let parent = world.entity(existing).get::<Parent>().unwrap().get();
let mut parent = world.entity_mut(parent);
let index = parent
.get::<Children>() .get::<Children>()
.unwrap() .unwrap()
.iter() .iter()
.position(|child| *child == existing) .position(|child| *child == existing)
.unwrap(); .unwrap();
parent.insert_children(index, &new_nodes); existing_parent.insert_children(existing_index, &stack.split_off(stack.len() - m));
DespawnRecursive { entity: existing }.apply(world); DespawnRecursive { entity: existing }.apply(world);
// TODO: We're not removing child entities from the element maps // 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(&existing) {
element_id_to_bevy_ui_entity.remove(&existing_element_id); element_id_to_bevy_ui_entity.remove(&existing_element_id);
} }
}, }
Mutation::ReplacePlaceholder { path, m } => { Mutation::ReplacePlaceholder { path, m } => {
let mut existing = stack[stack.len() - m - 1]; let mut existing = stack[stack.len() - m - 1];
for index in path { for index in path {
@ -120,8 +118,7 @@ pub fn apply_mutations(
.iter() .iter()
.position(|child| *child == existing) .position(|child| *child == existing)
.unwrap(); .unwrap();
let new = stack.drain((stack.len() - m)..).collect::<Vec<Entity>>(); existing_parent.insert_children(existing_index, &stack.split_off(stack.len() - m));
existing_parent.insert_children(existing_index, &new);
DespawnRecursive { entity: existing }.apply(world); DespawnRecursive { entity: existing }.apply(world);
// TODO: We're not removing child entities from the element maps // TODO: We're not removing child entities from the element maps
@ -133,20 +130,16 @@ pub fn apply_mutations(
let entity = element_id_to_bevy_ui_entity[&id]; let entity = element_id_to_bevy_ui_entity[&id];
let parent = world.entity(entity).get::<Parent>().unwrap().get(); let parent = world.entity(entity).get::<Parent>().unwrap().get();
let mut parent = world.entity_mut(parent); let mut parent = world.entity_mut(parent);
let index = parent let index = parent
.get::<Children>() .get::<Children>()
.unwrap() .unwrap()
.iter() .iter()
.position(|child| *child == entity) .position(|child| *child == entity)
.unwrap(); .unwrap();
let new = stack.drain((stack.len() - m)..).collect::<Vec<Entity>>(); parent.insert_children(index + 1, &stack.split_off(stack.len() - m));
parent.insert_children(index + 1, &new);
} }
Mutation::InsertBefore { id, m } => { Mutation::InsertBefore { id, m } => {
let new_nodes = stack.split_off(stack.len() - m);
let existing = element_id_to_bevy_ui_entity[&id]; let existing = element_id_to_bevy_ui_entity[&id];
let parent = world.entity(existing).get::<Parent>().unwrap().get(); let parent = world.entity(existing).get::<Parent>().unwrap().get();
let mut parent = world.entity_mut(parent); let mut parent = world.entity_mut(parent);
let index = parent let index = parent
@ -155,7 +148,7 @@ pub fn apply_mutations(
.iter() .iter()
.position(|child| *child == existing) .position(|child| *child == existing)
.unwrap(); .unwrap();
parent.insert_children(index, &new_nodes); parent.insert_children(index, &stack.split_off(stack.len() - m));
} }
Mutation::SetAttribute { Mutation::SetAttribute {
name, name,
@ -188,13 +181,10 @@ pub fn apply_mutations(
} }
Mutation::RemoveEventListener { .. } => {} Mutation::RemoveEventListener { .. } => {}
Mutation::Remove { id } => { Mutation::Remove { id } => {
let existing = element_id_to_bevy_ui_entity[&id]; let entity = element_id_to_bevy_ui_entity[&id];
DespawnRecursive { DespawnRecursive { entity }.apply(world);
entity: existing,
}
.apply(world);
// TODO: We're not removing child entities from the element maps // 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); element_id_to_bevy_ui_entity.remove(&existing_element_id);
} }
} }