Skip to content
Snippets Groups Projects
Commit a6492787 authored by John Mitchell's avatar John Mitchell
Browse files

Help the entity hierarchy to be a bit cleaner for `PreviousWidget`.

parent 5d4ca7a1
No related branches found
No related tags found
No related merge requests found
......@@ -865,20 +865,34 @@ fn update_widget(
) -> (Tree, bool) {
// Check if we should update this widget
let should_rerender = {
// TODO: Move the spawning to when we create the widget.
let old_props_entity =
if let Ok(mut cloned_widget_entities) = cloned_widget_entities.try_write() {
if let Some(entity) = cloned_widget_entities.get(&entity.0).cloned() {
let old_parent_entity = if let Ok(tree) = tree.try_read() {
if let Some(parent_entity) = tree.get_parent(entity) {
cloned_widget_entities.get(&parent_entity.0).copied()
} else {
None
}
} else { None };
if let Some(entity) = cloned_widget_entities.get(&entity.0).copied() {
if let Some(possible_entity) = world.get_entity(entity) {
let target = possible_entity.id();
cloned_widget_entities.insert(entity, target);
target
} else {
let target = world.spawn_empty().insert(PreviousWidget).id();
if let Some(parent_id) = old_parent_entity {
world.entity_mut(parent_id).add_child(target);
}
cloned_widget_entities.insert(entity, target);
target
}
} else {
let target = world.spawn_empty().insert(PreviousWidget).id();
if let Some(parent_id) = old_parent_entity {
world.entity_mut(parent_id).add_child(target);
}
cloned_widget_entities.insert(entity.0, target);
target
}
......
use bevy::prelude::{Bundle, Commands, Component, Entity, In, Query, Vec2};
use bevy::prelude::{Bundle, Commands, Component, Entity, In, Query, Vec2, BuildChildren};
use crate::{
children::KChildren,
......@@ -173,7 +173,7 @@ pub fn scroll_context_render(
)>,
) -> bool {
if let Ok((context_provider, children, styles, mut computed_styles)) = query.get_mut(entity) {
let context_entity = commands.spawn(context_provider.initial_value).id();
let context_entity = commands.spawn(context_provider.initial_value).set_parent(entity).id();
widget_context.set_context_entity::<ScrollContext>(Some(entity), context_entity);
*computed_styles = styles.clone().into();
children.process(&widget_context, Some(entity));
......
......@@ -76,7 +76,7 @@ pub fn window_context_render(
{
context_entity
} else {
commands.spawn(WindowContext::default()).id()
commands.spawn(WindowContext::default()).set_parent(window_context_entity).id()
};
widget_context
.set_context_entity::<WindowContext>(Some(window_context_entity), context_entity);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment