Skip to content

Commit c5742ff

Browse files
ickshonpeoceantumealice-i-cecileUkoeHB
authored
Simplified ui_stack_system (#9889)
# Objective `ui_stack_system` generates a tree of `StackingContexts` which it then flattens to get the `UiStack`. But there's no need to construct a new tree. We can query for nodes with a global `ZIndex`, add those nodes to the root nodes list and then build the `UiStack` from a walk of the existing layout tree, ignoring any branches that have a global `Zindex`. Fixes #9877 ## Solution Split the `ZIndex` enum into two separate components, `ZIndex` and `GlobalZIndex` Query for nodes with a `GlobalZIndex`, add those nodes to the root nodes list and then build the `UiStack` from a walk of the existing layout tree, filtering branches by `Without<GlobalZIndex>` so we don't revisit nodes. ``` cargo run --profile stress-test --features trace_tracy --example many_buttons ``` <img width="672" alt="ui-stack-system-walk-split-enum" src="https://github.com/bevyengine/bevy/assets/27962798/11e357a5-477f-4804-8ada-c4527c009421"> (Yellow is this PR, red is main) --- ## Changelog `Zindex` * The `ZIndex` enum has been split into two separate components `ZIndex` (which replaces `ZIndex::Local`) and `GlobalZIndex` (which replaces `ZIndex::Global`). An entity can have both a `ZIndex` and `GlobalZIndex`, in comparisons `ZIndex` breaks ties if two `GlobalZIndex` values are equal. `ui_stack_system` * Instead of generating a tree of `StackingContexts`, query for nodes with a `GlobalZIndex`, add those nodes to the root nodes list and then build the `UiStack` from a walk of the existing layout tree, filtering branches by `Without<GlobalZIndex` so we don't revisit nodes. ## Migration Guide The `ZIndex` enum has been split into two separate components `ZIndex` (which replaces `ZIndex::Local`) and `GlobalZIndex` (which replaces `ZIndex::Global`). An entity can have both a `ZIndex` and `GlobalZIndex`, in comparisons `ZIndex` breaks ties if two `GlobalZindex` values are equal. --------- Co-authored-by: Gabriel Bourgeois <[email protected]> Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: UkoeHB <[email protected]>
1 parent 93aa2a2 commit c5742ff

File tree

6 files changed

+240
-199
lines changed

6 files changed

+240
-199
lines changed

crates/bevy_dev_tools/src/fps_overlay.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use bevy_render::view::Visibility;
1616
use bevy_text::{Font, Text, TextSection, TextStyle};
1717
use bevy_ui::{
1818
node_bundles::{NodeBundle, TextBundle},
19-
PositionType, Style, ZIndex,
19+
GlobalZIndex, PositionType, Style,
2020
};
2121
use bevy_utils::default;
2222

23-
/// Global [`ZIndex`] used to render the fps overlay.
23+
/// [`GlobalZIndex`] used to render the fps overlay.
2424
///
2525
/// We use a number slightly under `i32::MAX` so you can render on top of it if you really need to.
2626
pub const FPS_OVERLAY_ZINDEX: i32 = i32::MAX - 32;
@@ -83,16 +83,18 @@ struct FpsText;
8383

8484
fn setup(mut commands: Commands, overlay_config: Res<FpsOverlayConfig>) {
8585
commands
86-
.spawn(NodeBundle {
87-
style: Style {
88-
// We need to make sure the overlay doesn't affect the position of other UI nodes
89-
position_type: PositionType::Absolute,
86+
.spawn((
87+
NodeBundle {
88+
style: Style {
89+
// We need to make sure the overlay doesn't affect the position of other UI nodes
90+
position_type: PositionType::Absolute,
91+
..default()
92+
},
93+
// Render overlay on top of everything
9094
..default()
9195
},
92-
// Render overlay on top of everything
93-
z_index: ZIndex::Global(FPS_OVERLAY_ZINDEX),
94-
..default()
95-
})
96+
GlobalZIndex(FPS_OVERLAY_ZINDEX),
97+
))
9698
.with_children(|c| {
9799
c.spawn((
98100
TextBundle::from_sections([

0 commit comments

Comments
 (0)