mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Replace remaining uses of &T, Changed<T>
with Ref
in UI system queries (#8567)
# Objective Replace `Query<&T, Changed<T>>` style queries with the more efficient `Query<Ref<T>>` 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.
This commit is contained in:
parent
613b5a69ae
commit
8581f607f8
2 changed files with 21 additions and 19 deletions
|
@ -8,9 +8,10 @@ use bevy_a11y::{
|
||||||
};
|
};
|
||||||
use bevy_app::{App, Plugin, Update};
|
use bevy_app::{App, Plugin, Update};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
prelude::Entity,
|
prelude::{DetectChanges, Entity},
|
||||||
query::{Changed, Or, Without},
|
query::{Changed, Without},
|
||||||
system::{Commands, Query},
|
system::{Commands, Query},
|
||||||
|
world::Ref,
|
||||||
};
|
};
|
||||||
use bevy_hierarchy::Children;
|
use bevy_hierarchy::Children;
|
||||||
use bevy_render::prelude::Camera;
|
use bevy_render::prelude::Camera;
|
||||||
|
@ -34,13 +35,11 @@ fn calc_name(texts: &Query<&Text>, children: &Children) -> Option<Box<str>> {
|
||||||
|
|
||||||
fn calc_bounds(
|
fn calc_bounds(
|
||||||
camera: Query<(&Camera, &GlobalTransform)>,
|
camera: Query<(&Camera, &GlobalTransform)>,
|
||||||
mut nodes: Query<
|
mut nodes: Query<(&mut AccessibilityNode, Ref<Node>, Ref<GlobalTransform>)>,
|
||||||
(&mut AccessibilityNode, &Node, &GlobalTransform),
|
|
||||||
Or<(Changed<Node>, Changed<GlobalTransform>)>,
|
|
||||||
>,
|
|
||||||
) {
|
) {
|
||||||
if let Ok((camera, camera_transform)) = camera.get_single() {
|
if let Ok((camera, camera_transform)) = camera.get_single() {
|
||||||
for (mut accessible, node, transform) in &mut nodes {
|
for (mut accessible, node, transform) in &mut nodes {
|
||||||
|
if node.is_changed() || transform.is_changed() {
|
||||||
if let Some(translation) =
|
if let Some(translation) =
|
||||||
camera.world_to_viewport(camera_transform, transform.translation())
|
camera.world_to_viewport(camera_transform, transform.translation())
|
||||||
{
|
{
|
||||||
|
@ -54,6 +53,7 @@ fn calc_bounds(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn button_changed(
|
fn button_changed(
|
||||||
|
|
|
@ -6,7 +6,7 @@ use bevy_ecs::{
|
||||||
change_detection::DetectChanges,
|
change_detection::DetectChanges,
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
event::EventReader,
|
event::EventReader,
|
||||||
query::{Changed, With, Without},
|
query::{With, Without},
|
||||||
removal_detection::RemovedComponents,
|
removal_detection::RemovedComponents,
|
||||||
system::{Query, Res, ResMut, Resource},
|
system::{Query, Res, ResMut, Resource},
|
||||||
world::Ref,
|
world::Ref,
|
||||||
|
@ -222,7 +222,7 @@ pub fn ui_layout_system(
|
||||||
root_node_query: Query<Entity, (With<Node>, Without<Parent>)>,
|
root_node_query: Query<Entity, (With<Node>, Without<Parent>)>,
|
||||||
style_query: Query<(Entity, Ref<Style>), With<Node>>,
|
style_query: Query<(Entity, Ref<Style>), With<Node>>,
|
||||||
mut measure_query: Query<(Entity, &mut ContentSize)>,
|
mut measure_query: Query<(Entity, &mut ContentSize)>,
|
||||||
children_query: Query<(Entity, &Children), (With<Node>, Changed<Children>)>,
|
children_query: Query<(Entity, Ref<Children>), With<Node>>,
|
||||||
mut removed_children: RemovedComponents<Children>,
|
mut removed_children: RemovedComponents<Children>,
|
||||||
mut removed_content_sizes: RemovedComponents<ContentSize>,
|
mut removed_content_sizes: RemovedComponents<ContentSize>,
|
||||||
mut node_transform_query: Query<(Entity, &mut Node, &mut Transform, Option<&Parent>)>,
|
mut node_transform_query: Query<(Entity, &mut Node, &mut Transform, Option<&Parent>)>,
|
||||||
|
@ -293,7 +293,9 @@ pub fn ui_layout_system(
|
||||||
ui_surface.try_remove_children(entity);
|
ui_surface.try_remove_children(entity);
|
||||||
}
|
}
|
||||||
for (entity, children) in &children_query {
|
for (entity, children) in &children_query {
|
||||||
ui_surface.update_children(entity, children);
|
if children.is_changed() {
|
||||||
|
ui_surface.update_children(entity, &children);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute layouts
|
// compute layouts
|
||||||
|
|
Loading…
Reference in a new issue