From 8581f607f8c3de042b470d79762cf7346e6eca79 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 8 May 2023 21:49:55 +0100 Subject: [PATCH] Replace remaining uses of `&T, Changed` with `Ref` in UI system queries (#8567) # Objective Replace `Query<&T, Changed>` style queries with the more efficient `Query>` form in two of the UI systems. --- ## Changelog Replaced use of `Changed` with `Ref` in queries in the `ui_layout_system` and `calc_bounds` UI systems. --- crates/bevy_ui/src/accessibility.rs | 32 ++++++++++++++--------------- crates/bevy_ui/src/layout/mod.rs | 8 +++++--- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/crates/bevy_ui/src/accessibility.rs b/crates/bevy_ui/src/accessibility.rs index 42b2137e9c..f54d2efff3 100644 --- a/crates/bevy_ui/src/accessibility.rs +++ b/crates/bevy_ui/src/accessibility.rs @@ -8,9 +8,10 @@ use bevy_a11y::{ }; use bevy_app::{App, Plugin, Update}; use bevy_ecs::{ - prelude::Entity, - query::{Changed, Or, Without}, + prelude::{DetectChanges, Entity}, + query::{Changed, Without}, system::{Commands, Query}, + world::Ref, }; use bevy_hierarchy::Children; use bevy_render::prelude::Camera; @@ -34,23 +35,22 @@ fn calc_name(texts: &Query<&Text>, children: &Children) -> Option> { fn calc_bounds( camera: Query<(&Camera, &GlobalTransform)>, - mut nodes: Query< - (&mut AccessibilityNode, &Node, &GlobalTransform), - Or<(Changed, Changed)>, - >, + mut nodes: Query<(&mut AccessibilityNode, Ref, Ref)>, ) { if let Ok((camera, camera_transform)) = camera.get_single() { for (mut accessible, node, transform) in &mut nodes { - if let Some(translation) = - camera.world_to_viewport(camera_transform, transform.translation()) - { - let bounds = Rect::new( - translation.x.into(), - translation.y.into(), - (translation.x + node.calculated_size.x).into(), - (translation.y + node.calculated_size.y).into(), - ); - accessible.set_bounds(bounds); + if node.is_changed() || transform.is_changed() { + if let Some(translation) = + camera.world_to_viewport(camera_transform, transform.translation()) + { + let bounds = Rect::new( + translation.x.into(), + translation.y.into(), + (translation.x + node.calculated_size.x).into(), + (translation.y + node.calculated_size.y).into(), + ); + accessible.set_bounds(bounds); + } } } } diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index b1556515eb..14da00866d 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -6,7 +6,7 @@ use bevy_ecs::{ change_detection::DetectChanges, entity::Entity, event::EventReader, - query::{Changed, With, Without}, + query::{With, Without}, removal_detection::RemovedComponents, system::{Query, Res, ResMut, Resource}, world::Ref, @@ -222,7 +222,7 @@ pub fn ui_layout_system( root_node_query: Query, Without)>, style_query: Query<(Entity, Ref