Handle UI Nodes becoming a child of another UI node Added<Parent>
Handle UI Nodes who lose their parent to become a root UI node RemovedComponent<Parent>
Solution
Extends the queries for the layout_system and various system params to capture and handle these events.
Testing
Did you test these changes? If so, how?
Unit tests and example
Are there any parts that need more testing?
Unknown
How can other people (reviewers) test your changes? Is there anything specific they need to know?
Run example code below, apply diff to see before and after behavior
Click to view diff
```diff
Index: crates/bevy_ui/src/layout/mod.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs
--- a/crates/bevy_ui/src/layout/mod.rs (revision Staged)
+++ b/crates/bevy_ui/src/layout/mod.rs (date 1731545949320)
@@ -210,11 +210,11 @@
.filter(|&entity| root_nodes.is_root_node(entity));
for entity in promoted_root_ui_nodes {
- ui_surface.promote_ui_node(entity);
+ // ui_surface.promote_ui_node(entity);
}
for (entity, parent) in root_nodes.iter_demoted_root_nodes() {
- ui_surface.demote_ui_node(entity, parent.get());
+ // ui_surface.demote_ui_node(entity, parent.get());
}
// When a `ContentSize` component is removed from an entity, we need to remove the measure from the corresponding taffy node.
```
supersedes https://github.com/bevyengine/bevy/pull/13360
Objective
Added<Parent>
RemovedComponent<Parent>
Solution
Testing
Unit tests and example
Unknown
Run example code below, apply diff to see before and after behavior
Click to view diff
```diff Index: crates/bevy_ui/src/layout/mod.rs IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs --- a/crates/bevy_ui/src/layout/mod.rs (revision Staged) +++ b/crates/bevy_ui/src/layout/mod.rs (date 1731545949320) @@ -210,11 +210,11 @@ .filter(|&entity| root_nodes.is_root_node(entity)); for entity in promoted_root_ui_nodes { - ui_surface.promote_ui_node(entity); + // ui_surface.promote_ui_node(entity); } for (entity, parent) in root_nodes.iter_demoted_root_nodes() { - ui_surface.demote_ui_node(entity, parent.get()); + // ui_surface.demote_ui_node(entity, parent.get()); } // When a `ContentSize` component is removed from an entity, we need to remove the measure from the corresponding taffy node. ```Example
Click to view example
```rust //! Demonstrates how UI can handle non-standard hierarchy changes use bevy::ecs::query::QueryData; use bevy::{color::palettes::css::*, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, spawn_layout) .add_systems(Update, input) .run(); } #[derive(Component, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)] struct Id(usize); #[derive(Component, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)] struct Pos(usize); impl Pos { fn set(&mut self, pos: usize) { self.0 = pos; } fn get(&self) -> usize { self.0 } } #[derive(Component, Debug, Copy, Clone)] struct Marker; const COLS: usize = 3; fn spawn_layout(mut commands: Commands) { commands.spawn(Camera2d); let grid_template_columns = (0..COLS).map(|_| GridTrack::flex(1.0)).collect::