This commit is contained in:
JMS55 2023-12-20 22:46:34 -08:00
parent 35e9b0f827
commit cfc92ecb55
2 changed files with 13 additions and 7 deletions

View file

@ -1,4 +1,4 @@
use crate::events::is_supported_event; use crate::{events::is_supported_event, tick::IntrinsicTextNode};
use bevy::{ use bevy::{
ecs::{entity::Entity, system::Command, world::World}, ecs::{entity::Entity, system::Command, world::World},
hierarchy::{BuildWorldChildren, Children, DespawnRecursive, Parent}, hierarchy::{BuildWorldChildren, Children, DespawnRecursive, Parent},
@ -323,10 +323,13 @@ impl BevyTemplateNode {
.id() .id()
} }
Self::IntrinsicTextNode(text) => world Self::IntrinsicTextNode(text) => world
.spawn(TextBundle { .spawn((
text: text.clone(), TextBundle {
..default() text: text.clone(),
}) ..default()
},
IntrinsicTextNode,
))
.id(), .id(),
} }
} }

View file

@ -4,11 +4,11 @@ use crate::{
}; };
use bevy::{ use bevy::{
ecs::{ ecs::{
component::Component,
entity::Entity, entity::Entity,
world::{Mut, World}, world::{Mut, World},
}, },
hierarchy::Parent, hierarchy::Parent,
text::Text,
utils::HashMap, utils::HashMap,
}; };
use std::{any::Any, mem, rc::Rc, sync::Arc}; use std::{any::Any, mem, rc::Rc, sync::Arc};
@ -68,7 +68,7 @@ fn dispatch_ui_events(
) { ) {
for (mut target, name, data) in events { for (mut target, name, data) in events {
let mut target_element_id = ui_root.bevy_ui_entity_to_element_id.get(&target).copied(); let mut target_element_id = ui_root.bevy_ui_entity_to_element_id.get(&target).copied();
while target_element_id.is_none() || world.entity(target).contains::<Text>() { while target_element_id.is_none() || world.entity(target).contains::<IntrinsicTextNode>() {
target = world.entity(target).get::<Parent>().unwrap().get(); target = world.entity(target).get::<Parent>().unwrap().get();
target_element_id = ui_root.bevy_ui_entity_to_element_id.get(&target).copied(); target_element_id = ui_root.bevy_ui_entity_to_element_id.get(&target).copied();
} }
@ -122,3 +122,6 @@ fn render_ui(root_entity: Entity, ui_root: &mut UiRoot, world: &mut World) {
world, world,
); );
} }
#[derive(Component)]
pub struct IntrinsicTextNode;