11//! This module contains systems that update the UI when something changes
22
3- use crate :: { CalculatedClip , Overflow , Style } ;
3+ use crate :: { entity :: UiCameraConfig , CalculatedClip , Overflow , Style } ;
44
55use super :: Node ;
66use bevy_ecs:: {
@@ -10,6 +10,7 @@ use bevy_ecs::{
1010} ;
1111use bevy_hierarchy:: { Children , Parent } ;
1212use bevy_math:: Vec2 ;
13+ use bevy_render:: view:: { ComputedVisibility , RenderLayers } ;
1314use bevy_sprite:: Rect ;
1415use bevy_transform:: components:: { GlobalTransform , Transform } ;
1516
@@ -64,6 +65,30 @@ fn update_hierarchy(
6465 current_global_z
6566}
6667
68+ /// Correct the `ComputedVisibility` set by [`check_visibility`] for UI nodes.
69+ ///
70+ /// Since [`check_visibility`] has no concept of UI cameras, we need a "post-pass"
71+ /// where we re-enable UI nodes that are visible because they have a matching
72+ /// UI camera in their layer.
73+ ///
74+ /// [`check_visibility`]: bevy_render::view::visibility::check_visibility
75+ pub fn update_layer_visibility (
76+ ui_cams : Query < & UiCameraConfig > ,
77+ mut nodes : Query < ( & mut ComputedVisibility , & RenderLayers ) , With < Node > > ,
78+ ) {
79+ for config in & ui_cams {
80+ // Skip configs with default render layers, since `check_visibility` assumes it
81+ if config. ui_render_layers == RenderLayers :: default ( ) {
82+ continue ;
83+ }
84+ for ( mut visibility, node_layers) in & mut nodes {
85+ if config. ui_render_layers . intersects ( node_layers) {
86+ visibility. set_visible_in_view ( ) ;
87+ }
88+ }
89+ }
90+ }
91+
6792/// Updates clipping for all nodes
6893pub fn update_clipping_system (
6994 mut commands : Commands ,
0 commit comments