From 00590e2f6d18d5ef27b13e7bf4e3830d58cb775a Mon Sep 17 00:00:00 2001 From: Viktor Gustavsson Date: Mon, 14 Oct 2024 18:28:16 +0200 Subject: [PATCH 01/18] Rename get_parent -> parent --- crates/bevy_ui/src/ghost_hierarchy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/ghost_hierarchy.rs b/crates/bevy_ui/src/ghost_hierarchy.rs index ad5a88948052a..303b2c481c788 100644 --- a/crates/bevy_ui/src/ghost_hierarchy.rs +++ b/crates/bevy_ui/src/ghost_hierarchy.rs @@ -77,7 +77,7 @@ impl<'w, 's> UiChildren<'w, 's> { } /// Returns the UI parent of the provided entity, skipping over [`GhostNode`]. - pub fn get_parent(&'s self, entity: Entity) -> Option { + pub fn parent(&'s self, entity: Entity) -> Option { self.parents_query .iter_ancestors(entity) .find(|entity| !self.ghost_nodes_query.contains(*entity)) From 41592e1041a3dd47569320f55a6a0ee193fb3cf9 Mon Sep 17 00:00:00 2001 From: Viktor Gustavsson Date: Mon, 14 Oct 2024 18:31:02 +0200 Subject: [PATCH 02/18] Rename iter_ui_children -> iter_children --- crates/bevy_ui/src/accessibility.rs | 4 ++-- crates/bevy_ui/src/ghost_hierarchy.rs | 10 ++++------ crates/bevy_ui/src/layout/mod.rs | 6 +++--- crates/bevy_ui/src/stack.rs | 2 +- crates/bevy_ui/src/update.rs | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/bevy_ui/src/accessibility.rs b/crates/bevy_ui/src/accessibility.rs index 2a5944f40a371..cfe0af7bc4e94 100644 --- a/crates/bevy_ui/src/accessibility.rs +++ b/crates/bevy_ui/src/accessibility.rs @@ -65,7 +65,7 @@ fn button_changed( mut text_reader: TextUiReader, ) { for (entity, accessible) in &mut query { - let name = calc_name(&mut text_reader, ui_children.iter_ui_children(entity)); + let name = calc_name(&mut text_reader, ui_children.iter_children(entity)); if let Some(mut accessible) = accessible { accessible.set_role(Role::Button); if let Some(name) = name { @@ -92,7 +92,7 @@ fn image_changed( mut text_reader: TextUiReader, ) { for (entity, accessible) in &mut query { - let name = calc_name(&mut text_reader, ui_children.iter_ui_children(entity)); + let name = calc_name(&mut text_reader, ui_children.iter_children(entity)); if let Some(mut accessible) = accessible { accessible.set_role(Role::Image); if let Some(name) = name { diff --git a/crates/bevy_ui/src/ghost_hierarchy.rs b/crates/bevy_ui/src/ghost_hierarchy.rs index 303b2c481c788..4745e7b542cbe 100644 --- a/crates/bevy_ui/src/ghost_hierarchy.rs +++ b/crates/bevy_ui/src/ghost_hierarchy.rs @@ -36,7 +36,7 @@ impl<'w, 's> UiRootNodes<'w, 's> { .iter() .chain(self.root_ghost_node_query.iter().flat_map(|root_ghost| { self.all_nodes_query - .iter_many(self.ui_children.iter_ui_children(root_ghost)) + .iter_many(self.ui_children.iter_children(root_ghost)) })) } } @@ -57,14 +57,14 @@ pub struct UiChildren<'w, 's> { } impl<'w, 's> UiChildren<'w, 's> { - /// Iterates the children of `entity`, skipping over [`GhostNode`]. + /// Iterates the [`Node`] children of `entity`, skipping over [`GhostNode`]. /// /// Traverses the hierarchy depth-first to ensure child order. /// /// # Performance /// /// This iterator allocates if the `entity` node has more than 8 children (including ghost nodes). - pub fn iter_ui_children(&'s self, entity: Entity) -> UiChildrenIter<'w, 's> { + pub fn iter_children(&'s self, entity: Entity) -> UiChildrenIter<'w, 's> { UiChildrenIter { stack: self .ui_children_query @@ -214,9 +214,7 @@ mod tests { let mut system_state = SystemState::<(UiChildren, Query<&A>)>::new(world); let (ui_children, a_query) = system_state.get(world); - let result: Vec<_> = a_query - .iter_many(ui_children.iter_ui_children(n1)) - .collect(); + let result: Vec<_> = a_query.iter_many(ui_children.iter_children(n1)).collect(); assert_eq!([&A(5), &A(4), &A(8), &A(10)], result.as_slice()); } diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index 492f1c1e0f2d4..146e7a56d3c87 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -263,7 +263,7 @@ with UI components as a child of an entity without UI components, your UI layout } if ui_children.is_changed(entity) { - ui_surface.update_children(entity, ui_children.iter_ui_children(entity)); + ui_surface.update_children(entity, ui_children.iter_children(entity)); } }); @@ -275,7 +275,7 @@ with UI components as a child of an entity without UI components, your UI layout // Re-sync changed children: avoid layout glitches caused by removed nodes that are still set as a child of another node node_query.iter().for_each(|(entity, _)| { if ui_children.is_changed(entity) { - ui_surface.update_children(entity, ui_children.iter_ui_children(entity)); + ui_surface.update_children(entity, ui_children.iter_children(entity)); } }); @@ -435,7 +435,7 @@ with UI components as a child of an entity without UI components, your UI layout .insert(ScrollPosition::from(&clamped_scroll_position)); } - for child_uinode in ui_children.iter_ui_children(entity) { + for child_uinode in ui_children.iter_children(entity) { update_uinode_geometry_recursive( commands, child_uinode, diff --git a/crates/bevy_ui/src/stack.rs b/crates/bevy_ui/src/stack.rs index a8d535fa2ff27..81b627fba342d 100644 --- a/crates/bevy_ui/src/stack.rs +++ b/crates/bevy_ui/src/stack.rs @@ -107,7 +107,7 @@ fn update_uistack_recursive( let mut child_buffer = cache.pop(); child_buffer.extend( ui_children - .iter_ui_children(node_entity) + .iter_children(node_entity) .filter_map(|child_entity| { zindex_query .get(child_entity) diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index 87abca8ad96de..d72fd7cdec379 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -105,7 +105,7 @@ fn update_clipping( Some(maybe_inherited_clip.map_or(node_rect, |c| c.intersect(node_rect))) }; - for child in ui_children.iter_ui_children(entity) { + for child in ui_children.iter_children(entity) { update_clipping(commands, ui_children, node_query, child, children_clip); } } @@ -164,7 +164,7 @@ fn update_children_target_camera( commands: &mut Commands, updated_entities: &mut HashSet, ) { - for child in ui_children.iter_ui_children(entity) { + for child in ui_children.iter_children(entity) { // Skip if the child has already been updated or update is not needed if updated_entities.contains(&child) || camera_to_set == node_query.get(child).ok().and_then(|(_, camera)| camera) From 4e4048713e677a72c6bb6cc3a41679d297f71500 Mon Sep 17 00:00:00 2001 From: Viktor Gustavsson Date: Mon, 14 Oct 2024 18:32:58 +0200 Subject: [PATCH 03/18] Rename is_ui_node -> is_ui_entity --- crates/bevy_ui/src/ghost_hierarchy.rs | 2 +- crates/bevy_ui/src/layout/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/ghost_hierarchy.rs b/crates/bevy_ui/src/ghost_hierarchy.rs index 4745e7b542cbe..1c87a64e6f2d9 100644 --- a/crates/bevy_ui/src/ghost_hierarchy.rs +++ b/crates/bevy_ui/src/ghost_hierarchy.rs @@ -108,7 +108,7 @@ impl<'w, 's> UiChildren<'w, 's> { } /// Returns `true` if the given entity is either a [`Node`] or a [`GhostNode`]. - pub fn is_ui_node(&'s self, entity: Entity) -> bool { + pub fn is_ui_entity(&'s self, entity: Entity) -> bool { self.ui_children_query.contains(entity) } } diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index 146e7a56d3c87..c72111867da53 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -254,7 +254,7 @@ pub fn ui_layout_system( // Note: This does not cover the case where a parent's Node component was removed. // Users are responsible for fixing hierarchies if they do that (it is not recommended). // Detecting it here would be a permanent perf burden on the hot path. - if parent.is_changed() && !ui_children.is_ui_node(parent.get()) { + if parent.is_changed() && !ui_children.is_ui_entity(parent.get()) { warn!( "Styled child ({entity}) in a non-UI entity hierarchy. You are using an entity \ with UI components as a child of an entity without UI components, your UI layout may be broken." From d2a0e557649a9c175f4b475539978b1875b34a08 Mon Sep 17 00:00:00 2001 From: Viktor Gustavsson Date: Mon, 14 Oct 2024 18:35:18 +0200 Subject: [PATCH 04/18] Rename is_changed -> children_is_changed --- crates/bevy_ui/src/ghost_hierarchy.rs | 2 +- crates/bevy_ui/src/layout/mod.rs | 4 ++-- crates/bevy_ui/src/update.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ui/src/ghost_hierarchy.rs b/crates/bevy_ui/src/ghost_hierarchy.rs index 1c87a64e6f2d9..e993551378266 100644 --- a/crates/bevy_ui/src/ghost_hierarchy.rs +++ b/crates/bevy_ui/src/ghost_hierarchy.rs @@ -100,7 +100,7 @@ impl<'w, 's> UiChildren<'w, 's> { } /// Given an entity in the UI hierarchy, check if its set of children has changed, e.g if children has been added/removed or if the order has changed. - pub fn is_changed(&'s self, entity: Entity) -> bool { + pub fn children_is_changed(&'s self, entity: Entity) -> bool { self.changed_children_query.contains(entity) || self .iter_ghost_nodes(entity) diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index c72111867da53..28981333211c0 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -262,7 +262,7 @@ with UI components as a child of an entity without UI components, your UI layout } } - if ui_children.is_changed(entity) { + if ui_children.children_is_changed(entity) { ui_surface.update_children(entity, ui_children.iter_children(entity)); } }); @@ -274,7 +274,7 @@ with UI components as a child of an entity without UI components, your UI layout // Re-sync changed children: avoid layout glitches caused by removed nodes that are still set as a child of another node node_query.iter().for_each(|(entity, _)| { - if ui_children.is_changed(entity) { + if ui_children.children_is_changed(entity) { ui_surface.update_children(entity, ui_children.iter_children(entity)); } }); diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index d72fd7cdec379..f47e808acd1de 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -141,7 +141,7 @@ pub fn update_target_camera_system( // by this point, and iteration will be skipped. // Otherwise, update changed children for (parent, target_camera) in &node_query { - if !ui_children.is_changed(parent) { + if !ui_children.children_is_changed(parent) { continue; } From 457153279059bc2eaf81c64d36af0a5fbb58dbad Mon Sep 17 00:00:00 2001 From: Viktor Gustavsson Date: Mon, 14 Oct 2024 18:40:40 +0200 Subject: [PATCH 05/18] Rename ghost_hierarchy -> ui_tree --- crates/bevy_ui/src/lib.rs | 4 ++-- crates/bevy_ui/src/{ghost_hierarchy.rs => ui_tree.rs} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename crates/bevy_ui/src/{ghost_hierarchy.rs => ui_tree.rs} (100%) diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 007959402ba8b..3f28330730cac 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -26,20 +26,20 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; mod accessibility; mod focus; mod geometry; -mod ghost_hierarchy; mod layout; mod render; mod stack; mod ui_node; +mod ui_tree; pub use focus::*; pub use geometry::*; -pub use ghost_hierarchy::*; pub use layout::*; pub use measurement::*; pub use render::*; pub use ui_material::*; pub use ui_node::*; +pub use ui_tree::*; use widget::UiImageSize; /// The UI prelude. diff --git a/crates/bevy_ui/src/ghost_hierarchy.rs b/crates/bevy_ui/src/ui_tree.rs similarity index 100% rename from crates/bevy_ui/src/ghost_hierarchy.rs rename to crates/bevy_ui/src/ui_tree.rs From 72ffa1e4bdcd81a349b5b7d6297e9ec24a88a648 Mon Sep 17 00:00:00 2001 From: Viktor Gustavsson Date: Mon, 14 Oct 2024 18:45:51 +0200 Subject: [PATCH 06/18] Rename UiChildren -> UiTree --- crates/bevy_ui/src/accessibility.rs | 10 ++++----- crates/bevy_ui/src/layout/mod.rs | 22 ++++++++++---------- crates/bevy_ui/src/stack.rs | 12 +++++------ crates/bevy_ui/src/ui_tree.rs | 14 ++++++------- crates/bevy_ui/src/update.rs | 32 ++++++++++++----------------- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/crates/bevy_ui/src/accessibility.rs b/crates/bevy_ui/src/accessibility.rs index cfe0af7bc4e94..6599cde9f34d7 100644 --- a/crates/bevy_ui/src/accessibility.rs +++ b/crates/bevy_ui/src/accessibility.rs @@ -1,7 +1,7 @@ use crate::{ prelude::{Button, Label}, widget::TextUiReader, - Node, UiChildren, UiImage, + Node, UiImage, UiTree, }; use bevy_a11y::{ accesskit::{NodeBuilder, Rect, Role}, @@ -61,11 +61,11 @@ fn calc_bounds( fn button_changed( mut commands: Commands, mut query: Query<(Entity, Option<&mut AccessibilityNode>), Changed