diff --git a/examples/demo.rs b/examples/demo.rs index b590769..7ab1d03 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -26,6 +26,7 @@ fn main() { #[component] fn Editor(cx: Scope) -> Element { + // TODO: When selected entity is despawned, need to reset this to None let selected_entity = use_state(cx, || Option::<Entity>::None); render! { @@ -43,6 +44,7 @@ fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseState<Option<Entity>>) -> El render! { div { + onclick: move |_| selected_entity.set(None), flex_direction: "column", if entities.is_empty() { rsx! { "No entities exist" } diff --git a/src/apply_mutations.rs b/src/apply_mutations.rs index 85ed12e..41fb157 100644 --- a/src/apply_mutations.rs +++ b/src/apply_mutations.rs @@ -4,9 +4,10 @@ use bevy::{ hierarchy::{BuildWorldChildren, Children, DespawnRecursive, Parent}, prelude::default, render::color::Color, - text::{Text, TextStyle}, + text::{Text, TextLayoutInfo, TextStyle}, ui::{ node_bundles::{NodeBundle, TextBundle}, + widget::TextFlags, *, }, utils::{EntityHashMap, HashMap}, @@ -62,9 +63,12 @@ pub fn apply_mutations( for index in path { entity = world.entity(entity).get::<Children>().unwrap()[*index as usize]; } - world - .entity_mut(entity) - .insert(Text::from_section(value, TextStyle::default())); + world.entity_mut(entity).insert(( + Text::from_section(value, TextStyle::default()), + TextLayoutInfo::default(), + TextFlags::default(), + ContentSize::default(), + )); element_id_to_bevy_ui_entity.insert(id, entity); bevy_ui_entity_to_element_id.insert(entity, id); } @@ -93,6 +97,7 @@ pub fn apply_mutations( existing_parent.insert_children(existing_index, &new); 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); } @@ -182,7 +187,7 @@ impl BevyTemplateNode { Self::TextNode(Text::from_section(*text, TextStyle::default())) } TemplateNode::Dynamic { id: _ } => Self::Node { - style: Default::default(), + style: (Style::default(), Color::NONE.into()), children: Box::new([]), }, TemplateNode::DynamicText { id: _ } => {