From 859ef04526f788a1fd009e49aa553a0dff3369f3 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 8 Jan 2025 13:19:44 +0000 Subject: [PATCH 01/18] Added `UiCameraMap` and `UiCameraMapper` to wrap UI camera queries and use them more efficiently. --- crates/bevy_ui/src/render/mod.rs | 65 ++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 4a0147c32af2a..42e8b9903ebc8 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -20,6 +20,7 @@ use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d}; use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d}; use bevy_ecs::entity::{EntityHashMap, EntityHashSet}; use bevy_ecs::prelude::*; +use bevy_ecs::system::SystemParam; use bevy_image::prelude::*; use bevy_math::{FloatOrd, Mat4, Rect, UVec4, Vec2, Vec3, Vec3Swizzles, Vec4Swizzles}; use bevy_render::render_phase::ViewSortedRenderPhases; @@ -248,11 +249,54 @@ impl ExtractedUiNodes { } } +#[derive(SystemParam)] +pub struct UiCameraMap<'w, 's> { + default: DefaultUiCamera<'w, 's>, + mapping: Query<'w, 's, RenderEntity>, +} + +pub struct UiCameraMapper<'w, 's> { + mapping: &'s Query<'w, 's, RenderEntity>, + default_camera_entity: Option, + camera_entity: Entity, + render_entity: Entity, +} + +impl<'w, 's> UiCameraMapper<'w, 's> { + pub fn new(ui_camera_map: &'s UiCameraMap<'w, 's>) -> Self { + let default_camera_entity = ui_camera_map.default.get(); + Self { + mapping: &ui_camera_map.mapping, + default_camera_entity, + camera_entity: Entity::PLACEHOLDER, + render_entity: Entity::PLACEHOLDER, + } + } + + pub fn map(&mut self, camera: Option<&TargetCamera>) -> Option { + let Some(camera_entity) = camera + .map(TargetCamera::entity) + .or(self.default_camera_entity) + else { + return None; + }; + + if self.camera_entity != camera_entity { + let Ok(new_render_camera_entity) = self.mapping.get(camera_entity) else { + return None; + }; + self.render_entity = new_render_camera_entity; + self.camera_entity = camera_entity; + } + + Some(self.render_entity) + } +} + #[allow(clippy::too_many_arguments)] pub fn extract_uinode_background_colors( mut commands: Commands, mut extracted_uinodes: ResMut, - default_ui_camera: Extract, uinode_query: Extract< Query<( Entity, @@ -264,25 +308,22 @@ pub fn extract_uinode_background_colors( &BackgroundColor, )>, >, - mapping: Extract>, + camera_map: Extract, ) { - let default_camera_entity = default_ui_camera.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); + for (entity, uinode, transform, view_visibility, clip, camera, background_color) in &uinode_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { - continue; - }; - - let Ok(render_camera_entity) = mapping.get(camera_entity) else { - continue; - }; - // Skip invisible backgrounds if !view_visibility.get() || background_color.0.is_fully_transparent() { continue; } + let Some(camera_entity) = camera_mapper.map(camera) else { + continue; + }; + extracted_uinodes.uinodes.insert( commands.spawn(TemporaryRenderEntity).id(), ExtractedUiNode { @@ -294,7 +335,7 @@ pub fn extract_uinode_background_colors( }, clip: clip.map(|clip| clip.clip), image: AssetId::default(), - camera_entity: render_camera_entity, + camera_entity, item: ExtractedUiItem::Node { atlas_scaling: None, transform: transform.compute_matrix(), From 9564393742d213c89d973094bcd90687c5860820 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 8 Jan 2025 14:42:58 +0000 Subject: [PATCH 02/18] Use closure for mapper --- crates/bevy_ui/src/render/box_shadow.rs | 19 ++--- crates/bevy_ui/src/render/debug_overlay.rs | 10 +-- crates/bevy_ui/src/render/mod.rs | 73 +++++++++++-------- .../src/render/ui_material_pipeline.rs | 18 ++--- .../src/render/ui_texture_slice_pipeline.rs | 25 +++---- 5 files changed, 69 insertions(+), 76 deletions(-) diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index 515e06101581b..7ba96d17c83ca 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -34,7 +34,7 @@ use bevy_render::{ use bevy_transform::prelude::GlobalTransform; use bytemuck::{Pod, Zeroable}; -use super::{stack_z_offsets, QUAD_INDICES, QUAD_VERTEX_POSITIONS}; +use super::{stack_z_offsets, UiCameraMap, UiCameraMapper, QUAD_INDICES, QUAD_VERTEX_POSITIONS}; pub const BOX_SHADOW_SHADER_HANDLE: Handle = Handle::weak_from_u128(17717747047134343426); @@ -236,7 +236,6 @@ pub struct ExtractedBoxShadows { pub fn extract_shadows( mut commands: Commands, mut extracted_box_shadows: ResMut, - default_ui_camera: Extract, camera_query: Extract>, box_shadow_query: Extract< Query<( @@ -249,25 +248,21 @@ pub fn extract_shadows( Option<&TargetCamera>, )>, >, - mapping: Extract>, + camera_map: Extract, ) { - let default_camera_entity = default_ui_camera.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); for (entity, uinode, transform, view_visibility, box_shadow, clip, camera) in &box_shadow_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { - continue; - }; - - let Ok(camera_entity) = mapping.get(camera_entity) else { - continue; - }; - // Skip if no visible shadows if !view_visibility.get() || box_shadow.is_empty() || uinode.is_empty() { continue; } + let Some(camera_entity) = camera_mapper.map(camera) else { + continue; + }; + let ui_physical_viewport_size = camera_query .get(camera_entity) .ok() diff --git a/crates/bevy_ui/src/render/debug_overlay.rs b/crates/bevy_ui/src/render/debug_overlay.rs index 662d0d8d0e376..c05c7eeb42c7e 100644 --- a/crates/bevy_ui/src/render/debug_overlay.rs +++ b/crates/bevy_ui/src/render/debug_overlay.rs @@ -70,24 +70,20 @@ pub fn extract_debug_overlay( Option<&TargetCamera>, )>, >, - mapping: Extract>, + camera_map: Extract, ) { if !debug_options.enabled { return; } - let default_camera_entity = default_ui_camera.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); for (entity, uinode, visibility, maybe_clip, transform, camera) in &uinode_query { if !debug_options.show_hidden && !visibility.get() { continue; } - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { - continue; - }; - - let Ok(render_camera_entity) = mapping.get(camera_entity) else { + let Some(camera_entity) = camera_mapper.map(maybe_camera) else { continue; }; diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 42e8b9903ebc8..3e658cb8dbf8e 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -255,6 +255,31 @@ pub struct UiCameraMap<'w, 's> { mapping: Query<'w, 's, RenderEntity>, } +impl<'w, 's> UiCameraMap<'w, 's> { + pub fn get(&'w self) -> impl FnMut(Option<&TargetCamera>) -> Option + 'w { + let default_camera_entity = self.default.get(); + let mut current_camera_entity = Entity::PLACEHOLDER; + let mut current_render_entity = Entity::PLACEHOLDER; + + move |camera: Option<&TargetCamera>| { + let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) + else { + return None; + }; + + if current_camera_entity != camera_entity { + let Ok(new_render_camera_entity) = self.mapping.get(camera_entity) else { + return None; + }; + current_render_entity = new_render_camera_entity; + current_camera_entity = camera_entity; + } + + Some(current_render_entity) + } + } +} + pub struct UiCameraMapper<'w, 's> { mapping: &'s Query<'w, 's, RenderEntity>, default_camera_entity: Option, @@ -310,7 +335,7 @@ pub fn extract_uinode_background_colors( >, camera_map: Extract, ) { - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get(); for (entity, uinode, transform, view_visibility, clip, camera, background_color) in &uinode_query @@ -320,7 +345,7 @@ pub fn extract_uinode_background_colors( continue; } - let Some(camera_entity) = camera_mapper.map(camera) else { + let Some(camera_entity) = camera_mapper(camera) else { continue; }; @@ -356,7 +381,6 @@ pub fn extract_uinode_images( mut commands: Commands, mut extracted_uinodes: ResMut, texture_atlases: Extract>>, - default_ui_camera: Extract, uinode_query: Extract< Query<( Entity, @@ -368,18 +392,10 @@ pub fn extract_uinode_images( &ImageNode, )>, >, - mapping: Extract>, + camera_map: Extract, ) { - let default_camera_entity = default_ui_camera.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); for (entity, uinode, transform, view_visibility, clip, camera, image) in &uinode_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { - continue; - }; - - let Ok(render_camera_entity) = mapping.get(camera_entity) else { - continue; - }; - // Skip invisible images if !view_visibility.get() || image.color.is_fully_transparent() @@ -389,6 +405,10 @@ pub fn extract_uinode_images( continue; } + let Some(camera_entity) = camera_mapper.map(camera) else { + continue; + }; + let atlas_rect = image .texture_atlas .as_ref() @@ -426,7 +446,7 @@ pub fn extract_uinode_images( rect, clip: clip.map(|clip| clip.clip), image: image.image.id(), - camera_entity: render_camera_entity, + camera_entity, item: ExtractedUiItem::Node { atlas_scaling, transform: transform.compute_matrix(), @@ -445,7 +465,6 @@ pub fn extract_uinode_images( pub fn extract_uinode_borders( mut commands: Commands, mut extracted_uinodes: ResMut, - default_ui_camera: Extract, uinode_query: Extract< Query<( Entity, @@ -459,11 +478,12 @@ pub fn extract_uinode_borders( )>, >, parent_clip_query: Extract>, - mapping: Extract>, ui_children: UiChildren, + camera_map: Extract, ) { let image = AssetId::::default(); - let default_camera_entity = default_ui_camera.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); + for ( entity, node, @@ -475,22 +495,15 @@ pub fn extract_uinode_borders( (maybe_border_color, maybe_outline), ) in &uinode_query { - let Some(camera_entity) = maybe_camera - .map(TargetCamera::entity) - .or(default_camera_entity) - else { - continue; - }; - - let Ok(render_camera_entity) = mapping.get(camera_entity) else { - continue; - }; - // Skip invisible borders and removed nodes if !view_visibility.get() || node.display == Display::None { continue; } + let Some(camera_entity) = camera_mapper.map(maybe_camera) else { + continue; + }; + // Don't extract borders with zero width along all edges if computed_node.border() != BorderRect::ZERO { if let Some(border_color) = maybe_border_color.filter(|bc| !bc.0.is_fully_transparent()) @@ -506,7 +519,7 @@ pub fn extract_uinode_borders( }, image, clip: maybe_clip.map(|clip| clip.clip), - camera_entity: render_camera_entity, + camera_entity, item: ExtractedUiItem::Node { atlas_scaling: None, transform: global_transform.compute_matrix(), @@ -544,7 +557,7 @@ pub fn extract_uinode_borders( }, image, clip: parent_clip.map(|clip| clip.clip), - camera_entity: render_camera_entity, + camera_entity, item: ExtractedUiItem::Node { transform: global_transform.compute_matrix(), atlas_scaling: None, diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index 831cc71cd4d0b..b0879bc241b6a 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -362,7 +362,6 @@ pub fn extract_ui_material_nodes( mut commands: Commands, mut extracted_uinodes: ResMut>, materials: Extract>>, - default_ui_camera: Extract, uinode_query: Extract< Query<( Entity, @@ -374,20 +373,11 @@ pub fn extract_ui_material_nodes( Option<&TargetCamera>, )>, >, - render_entity_lookup: Extract>, + camera_map: Extract, ) { - // If there is only one camera, we use it as default - let default_single_camera = default_ui_camera.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); for (entity, uinode, transform, handle, view_visibility, clip, camera) in uinode_query.iter() { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_single_camera) else { - continue; - }; - - let Ok(camera_entity) = render_entity_lookup.get(camera_entity) else { - continue; - }; - // skip invisible nodes if !view_visibility.get() { continue; @@ -398,6 +388,10 @@ pub fn extract_ui_material_nodes( continue; } + let Some(camera_entity) = camera_mapper.map(camera) else { + continue; + }; + let border = [ uinode.border.left / uinode.size().x, uinode.border.right / uinode.size().x, diff --git a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs index 9bee1ea8df8fa..dfeb1618a3463 100644 --- a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs @@ -247,7 +247,6 @@ pub struct ExtractedUiTextureSlices { pub fn extract_ui_texture_slices( mut commands: Commands, mut extracted_ui_slicers: ResMut, - default_ui_camera: Extract, texture_atlases: Extract>>, slicers_query: Extract< Query<( @@ -260,18 +259,18 @@ pub fn extract_ui_texture_slices( &ImageNode, )>, >, - mapping: Extract>, + camera_map: Extract, ) { - let default_camera_entity = default_ui_camera.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); for (entity, uinode, transform, view_visibility, clip, camera, image) in &slicers_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) else { - continue; - }; - - let Ok(camera_entity) = mapping.get(camera_entity) else { + // Skip invisible images + if !view_visibility.get() + || image.color.is_fully_transparent() + || image.image.id() == TRANSPARENT_IMAGE_HANDLE.id() + { continue; - }; + } let image_scale_mode = match image.image_mode.clone() { widget::NodeImageMode::Sliced(texture_slicer) => { @@ -289,13 +288,9 @@ pub fn extract_ui_texture_slices( _ => continue, }; - // Skip invisible images - if !view_visibility.get() - || image.color.is_fully_transparent() - || image.image.id() == TRANSPARENT_IMAGE_HANDLE.id() - { + let Some(camera_entity) = camera_mapper.map(camera) else { continue; - } + }; let atlas_rect = image .texture_atlas From f6c371205d3339bd2d7b9c1e03e72c8bdc60a919 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 8 Jan 2025 14:58:10 +0000 Subject: [PATCH 03/18] Removed closure implementation. Added Doc comments. --- crates/bevy_ui/src/render/mod.rs | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 3e658cb8dbf8e..d59d89cc4f46b 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -255,31 +255,6 @@ pub struct UiCameraMap<'w, 's> { mapping: Query<'w, 's, RenderEntity>, } -impl<'w, 's> UiCameraMap<'w, 's> { - pub fn get(&'w self) -> impl FnMut(Option<&TargetCamera>) -> Option + 'w { - let default_camera_entity = self.default.get(); - let mut current_camera_entity = Entity::PLACEHOLDER; - let mut current_render_entity = Entity::PLACEHOLDER; - - move |camera: Option<&TargetCamera>| { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_camera_entity) - else { - return None; - }; - - if current_camera_entity != camera_entity { - let Ok(new_render_camera_entity) = self.mapping.get(camera_entity) else { - return None; - }; - current_render_entity = new_render_camera_entity; - current_camera_entity = camera_entity; - } - - Some(current_render_entity) - } - } -} - pub struct UiCameraMapper<'w, 's> { mapping: &'s Query<'w, 's, RenderEntity>, default_camera_entity: Option, @@ -288,6 +263,7 @@ pub struct UiCameraMapper<'w, 's> { } impl<'w, 's> UiCameraMapper<'w, 's> { + /// Get the default camera and create the mapper pub fn new(ui_camera_map: &'s UiCameraMap<'w, 's>) -> Self { let default_camera_entity = ui_camera_map.default.get(); Self { @@ -298,6 +274,7 @@ impl<'w, 's> UiCameraMapper<'w, 's> { } } + /// Returns the render entity corresponding to the given `TargetCamera` or the default camera if `None``. pub fn map(&mut self, camera: Option<&TargetCamera>) -> Option { let Some(camera_entity) = camera .map(TargetCamera::entity) @@ -335,7 +312,7 @@ pub fn extract_uinode_background_colors( >, camera_map: Extract, ) { - let mut camera_mapper = camera_map.get(); + let mut camera_mapper = UiCameraMapper::new(&camera_map); for (entity, uinode, transform, view_visibility, clip, camera, background_color) in &uinode_query @@ -345,7 +322,7 @@ pub fn extract_uinode_background_colors( continue; } - let Some(camera_entity) = camera_mapper(camera) else { + let Some(camera_entity) = camera_mapper.map(camera) else { continue; }; From dceba52f5152876da304daddd1e26e6863fcf137 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 8 Jan 2025 15:11:34 +0000 Subject: [PATCH 04/18] use 'w not 's lifetime param --- crates/bevy_ui/src/render/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index d59d89cc4f46b..ee9279b32c08e 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -256,7 +256,7 @@ pub struct UiCameraMap<'w, 's> { } pub struct UiCameraMapper<'w, 's> { - mapping: &'s Query<'w, 's, RenderEntity>, + mapping: &'w Query<'w, 's, RenderEntity>, default_camera_entity: Option, camera_entity: Entity, render_entity: Entity, @@ -264,7 +264,7 @@ pub struct UiCameraMapper<'w, 's> { impl<'w, 's> UiCameraMapper<'w, 's> { /// Get the default camera and create the mapper - pub fn new(ui_camera_map: &'s UiCameraMap<'w, 's>) -> Self { + pub fn new(ui_camera_map: &'w UiCameraMap<'w, 's>) -> Self { let default_camera_entity = ui_camera_map.default.get(); Self { mapping: &ui_camera_map.mapping, From ed61de6c05dec143c075839b775302b93120f749 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 8 Jan 2025 15:41:05 +0000 Subject: [PATCH 05/18] Added `current_camera` method to `UiCameraMapper` Fixed `boxed_shadow` camera query. --- crates/bevy_ui/src/render/box_shadow.rs | 4 ++-- crates/bevy_ui/src/render/mod.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index 7ba96d17c83ca..66c44efd7e9da 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -264,13 +264,13 @@ pub fn extract_shadows( }; let ui_physical_viewport_size = camera_query - .get(camera_entity) + .get(camera_mapper.current_camera()) .ok() .and_then(|(_, c)| { c.physical_viewport_size() .map(|size| Vec2::new(size.x as f32, size.y as f32)) }) - .unwrap_or(Vec2::ZERO); + .unwrap_or_else(|| Vec2::ZERO); let scale_factor = uinode.inverse_scale_factor.recip(); diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index ee9279b32c08e..652dbef14f6e2 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -293,6 +293,10 @@ impl<'w, 's> UiCameraMapper<'w, 's> { Some(self.render_entity) } + + pub fn current_camera(&self) -> Entity { + self.camera_entity + } } #[allow(clippy::too_many_arguments)] From 15e525a696152c6b348058bc72aeb34455e8710f Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 8 Jan 2025 20:56:57 +0000 Subject: [PATCH 06/18] Fixed syntax errors and imports after merge --- crates/bevy_ui/src/render/box_shadow.rs | 4 ++-- crates/bevy_ui/src/render/debug_overlay.rs | 7 +++---- crates/bevy_ui/src/render/ui_material_pipeline.rs | 2 +- crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index 7701d6e577af4..0948895c21251 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -3,7 +3,7 @@ use core::{hash::Hash, ops::Range}; use crate::{ - BoxShadow, BoxShadowSamples, CalculatedClip, ComputedNode, DefaultUiCamera, RenderUiSystem, + BoxShadow, BoxShadowSamples, CalculatedClip, ComputedNode, RenderUiSystem, ResolvedBorderRadius, TargetCamera, TransparentUi, Val, }; use bevy_app::prelude::*; @@ -27,7 +27,7 @@ use bevy_render::{ render_phase::*, render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, - sync_world::{RenderEntity, TemporaryRenderEntity}, + sync_world::TemporaryRenderEntity, view::*, Extract, ExtractSchedule, Render, RenderSet, }; diff --git a/crates/bevy_ui/src/render/debug_overlay.rs b/crates/bevy_ui/src/render/debug_overlay.rs index b33314dc14268..40ebe373f81fb 100644 --- a/crates/bevy_ui/src/render/debug_overlay.rs +++ b/crates/bevy_ui/src/render/debug_overlay.rs @@ -12,7 +12,6 @@ use bevy_ecs::system::ResMut; use bevy_ecs::system::Resource; use bevy_math::Rect; use bevy_math::Vec2; -use bevy_render::sync_world::RenderEntity; use bevy_render::sync_world::TemporaryRenderEntity; use bevy_render::view::ViewVisibility; use bevy_render::Extract; @@ -23,6 +22,7 @@ use super::ExtractedUiItem; use super::ExtractedUiNode; use super::ExtractedUiNodes; use super::NodeType; +use super::{UiCameraMap, UiCameraMapper}; /// Configuration for the UI debug overlay #[derive(Resource)] @@ -58,7 +58,6 @@ pub fn extract_debug_overlay( mut commands: Commands, debug_options: Extract>, mut extracted_uinodes: ResMut, - default_ui_camera: Extract, uinode_query: Extract< Query<( Entity, @@ -82,7 +81,7 @@ pub fn extract_debug_overlay( continue; } - let Some(camera_entity) = camera_mapper.map(maybe_camera) else { + let Some(camera_entity) = camera_mapper.map(camera) else { continue; }; @@ -101,7 +100,7 @@ pub fn extract_debug_overlay( .filter(|_| !debug_options.show_clipped) .map(|clip| clip.clip), image: AssetId::default(), - camera_entity: render_camera_entity, + camera_entity, item: ExtractedUiItem::Node { atlas_scaling: None, transform: transform.compute_matrix(), diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index a5a9c6059d795..5834142fb9df6 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -21,7 +21,7 @@ use bevy_render::{ render_phase::*, render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, - sync_world::{RenderEntity, TemporaryRenderEntity}, + sync_world::TemporaryRenderEntity, view::*, Extract, ExtractSchedule, Render, RenderSet, }; diff --git a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs index aadbe03c36db6..bb2e0e1021214 100644 --- a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs @@ -19,7 +19,7 @@ use bevy_render::{ render_phase::*, render_resource::{binding_types::uniform_buffer, *}, renderer::{RenderDevice, RenderQueue}, - sync_world::{RenderEntity, TemporaryRenderEntity}, + sync_world::TemporaryRenderEntity, texture::{GpuImage, TRANSPARENT_IMAGE_HANDLE}, view::*, Extract, ExtractSchedule, Render, RenderSet, From d6509925849660d24577b3955b493668b55dc808 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Sat, 11 Jan 2025 16:08:49 +0000 Subject: [PATCH 07/18] Removed unused import --- crates/bevy_ui/src/render/debug_overlay.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_ui/src/render/debug_overlay.rs b/crates/bevy_ui/src/render/debug_overlay.rs index 40ebe373f81fb..a176e30ebb9c1 100644 --- a/crates/bevy_ui/src/render/debug_overlay.rs +++ b/crates/bevy_ui/src/render/debug_overlay.rs @@ -1,6 +1,5 @@ use crate::CalculatedClip; use crate::ComputedNode; -use crate::DefaultUiCamera; use crate::TargetCamera; use bevy_asset::AssetId; use bevy_color::Hsla; From fded3a853e3080e7cad7c8a886acf2a9cc42b7cc Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Sat, 11 Jan 2025 16:12:31 +0000 Subject: [PATCH 08/18] removed unnecessary closure --- crates/bevy_ui/src/render/box_shadow.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index 0948895c21251..563968b2afd26 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -270,7 +270,7 @@ pub fn extract_shadows( c.physical_viewport_size() .map(|size| Vec2::new(size.x as f32, size.y as f32)) }) - .unwrap_or_else(|| Vec2::ZERO); + .unwrap_or(Vec2::ZERO); let scale_factor = uinode.inverse_scale_factor.recip(); From 2c49c5c7dd5a75cc484dfa123018702b38dbfd90 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 13 Jan 2025 21:58:50 +0000 Subject: [PATCH 09/18] Replaced the `new` function on `UiCameraMapper` with a `get_mapper` function on `UiCameraMap`. --- crates/bevy_ui/src/render/box_shadow.rs | 2 +- crates/bevy_ui/src/render/mod.rs | 43 +++++++++---------- .../src/render/ui_material_pipeline.rs | 2 +- .../src/render/ui_texture_slice_pipeline.rs | 2 +- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index 563968b2afd26..1a44d419c8299 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -250,7 +250,7 @@ pub fn extract_shadows( >, camera_map: Extract, ) { - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get_mapper(); for (entity, uinode, transform, view_visibility, box_shadow, clip, camera) in &box_shadow_query { diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 97ba396b5730d..754dda4275eac 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -255,6 +255,19 @@ pub struct UiCameraMap<'w, 's> { mapping: Query<'w, 's, RenderEntity>, } +impl<'w, 's> UiCameraMap<'w, 's> { + /// Get the default camera and create the mapper + pub fn get_mapper(&'w self) -> UiCameraMapper<'w, 's> { + let default_camera_entity = self.default.get(); + UiCameraMapper { + mapping: &self.mapping, + default_camera_entity, + camera_entity: Entity::PLACEHOLDER, + render_entity: Entity::PLACEHOLDER, + } + } +} + pub struct UiCameraMapper<'w, 's> { mapping: &'w Query<'w, 's, RenderEntity>, default_camera_entity: Option, @@ -263,17 +276,6 @@ pub struct UiCameraMapper<'w, 's> { } impl<'w, 's> UiCameraMapper<'w, 's> { - /// Get the default camera and create the mapper - pub fn new(ui_camera_map: &'w UiCameraMap<'w, 's>) -> Self { - let default_camera_entity = ui_camera_map.default.get(); - Self { - mapping: &ui_camera_map.mapping, - default_camera_entity, - camera_entity: Entity::PLACEHOLDER, - render_entity: Entity::PLACEHOLDER, - } - } - /// Returns the render entity corresponding to the given `TargetCamera` or the default camera if `None``. pub fn map(&mut self, camera: Option<&TargetCamera>) -> Option { let Some(camera_entity) = camera @@ -316,7 +318,7 @@ pub fn extract_uinode_background_colors( >, camera_map: Extract, ) { - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get_mapper(); for (entity, uinode, transform, view_visibility, clip, camera, background_color) in &uinode_query @@ -374,7 +376,7 @@ pub fn extract_uinode_images( >, camera_map: Extract, ) { - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get_mapper(); for (entity, uinode, transform, view_visibility, clip, camera, image) in &uinode_query { // Skip invisible images if !view_visibility.get() @@ -462,7 +464,7 @@ pub fn extract_uinode_borders( camera_map: Extract, ) { let image = AssetId::::default(); - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get_mapper(); for ( entity, @@ -650,7 +652,6 @@ pub fn extract_ui_camera_view( pub fn extract_text_sections( mut commands: Commands, mut extracted_uinodes: ResMut, - default_ui_camera: Extract, texture_atlases: Extract>>, uinode_query: Extract< Query<( @@ -665,12 +666,12 @@ pub fn extract_text_sections( )>, >, text_styles: Extract>, - mapping: Extract>, + camera_map: Extract, ) { let mut start = 0; let mut end = 1; - let default_ui_camera = default_ui_camera.get(); + let mut camera_mapper = camera_map.get_mapper(); for ( entity, uinode, @@ -682,16 +683,12 @@ pub fn extract_text_sections( text_layout_info, ) in &uinode_query { - let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera) else { - continue; - }; - // Skip if not visible or if size is set to zero (e.g. when a parent is set to `Display::None`) if !view_visibility.get() || uinode.is_empty() { continue; } - let Ok(&render_camera_entity) = mapping.get(camera_entity) else { + let Some(camera_entity) = camera_mapper.map(camera) else { continue; }; @@ -746,7 +743,7 @@ pub fn extract_text_sections( color, image: atlas_info.texture.id(), clip: clip.map(|clip| clip.clip), - camera_entity: render_camera_entity.id(), + camera_entity, rect, item: ExtractedUiItem::Glyphs { range: start..end }, main_entity: entity.into(), diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index 51078d0d8b97a..5b9e28096d2e6 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -375,7 +375,7 @@ pub fn extract_ui_material_nodes( >, camera_map: Extract, ) { - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get_mapper(); for (entity, uinode, transform, handle, view_visibility, clip, camera) in uinode_query.iter() { // skip invisible nodes diff --git a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs index c78d57c39ad45..aec4e3ff1b17d 100644 --- a/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs @@ -261,7 +261,7 @@ pub fn extract_ui_texture_slices( >, camera_map: Extract, ) { - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get_mapper(); for (entity, uinode, transform, view_visibility, clip, camera, image) in &slicers_query { // Skip invisible images From 5e824326fd33fdef35ecac2947ff141911eebd96 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 13 Jan 2025 22:57:09 +0000 Subject: [PATCH 10/18] Fixed debug overlay --- crates/bevy_ui/src/render/debug_overlay.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/render/debug_overlay.rs b/crates/bevy_ui/src/render/debug_overlay.rs index 8a6440bbfe670..82b757e495d97 100644 --- a/crates/bevy_ui/src/render/debug_overlay.rs +++ b/crates/bevy_ui/src/render/debug_overlay.rs @@ -21,7 +21,7 @@ use super::ExtractedUiItem; use super::ExtractedUiNode; use super::ExtractedUiNodes; use super::NodeType; -use super::{UiCameraMap, UiCameraMapper}; +use super::UiCameraMap; /// Configuration for the UI debug overlay #[derive(Resource)] @@ -73,7 +73,7 @@ pub fn extract_debug_overlay( return; } - let mut camera_mapper = UiCameraMapper::new(&camera_map); + let mut camera_mapper = camera_map.get_mapper(); for (entity, uinode, visibility, maybe_clip, transform, camera) in &uinode_query { if !debug_options.show_hidden && !visibility.get() { From 2bd2f8d96ef17d5a87f2a01623db17eabf8f39f0 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 14 Jan 2025 10:14:26 +0000 Subject: [PATCH 11/18] clippy fixes --- crates/bevy_ui/src/render/mod.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 35f39ca87a4d9..70bc6c874644d 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -279,14 +279,11 @@ pub struct UiCameraMapper<'w, 's> { } impl<'w, 's> UiCameraMapper<'w, 's> { - /// Returns the render entity corresponding to the given `TargetCamera` or the default camera if `None``. + /// Returns the render entity corresponding to the given `TargetCamera` or the default camera if `None`. pub fn map(&mut self, camera: Option<&TargetCamera>) -> Option { - let Some(camera_entity) = camera + let camera_entity = camera .map(TargetCamera::entity) - .or(self.default_camera_entity) - else { - return None; - }; + .or(self.default_camera_entity)?; if self.camera_entity != camera_entity { let Ok(new_render_camera_entity) = self.mapping.get(camera_entity) else { @@ -304,7 +301,6 @@ impl<'w, 's> UiCameraMapper<'w, 's> { } } -#[allow(clippy::too_many_arguments)] /// A [`RenderGraphNode`] that executes the UI rendering subgraph on the UI /// view. struct RunUiSubgraphOnUiViewNode; From 6c8f827b561e6b61ddf0384134388079298b40e8 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 16 Jan 2025 15:03:51 +0000 Subject: [PATCH 12/18] use `UiCameraMap` in `measure_text_system` --- crates/bevy_ui/src/widget/text.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 6706e25df8356..3dedfa491511e 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -1,6 +1,6 @@ use crate::{ ComputedNode, ContentSize, DefaultUiCamera, FixedMeasure, Measure, MeasureArgs, Node, - NodeMeasure, TargetCamera, UiScale, + NodeMeasure, TargetCamera, UiCameraMap, UiScale, }; use bevy_asset::Assets; use bevy_color::Color; @@ -246,7 +246,6 @@ pub fn measure_text_system( mut last_scale_factors: Local>, fonts: Res>, camera_query: Query<(Entity, &Camera)>, - default_ui_camera: DefaultUiCamera, ui_scale: Res, mut text_query: Query< ( @@ -262,16 +261,14 @@ pub fn measure_text_system( mut text_reader: TextUiReader, mut text_pipeline: ResMut, mut font_system: ResMut, + ui_camera_map: UiCameraMap, ) { scale_factors_buffer.clear(); - let default_camera_entity = default_ui_camera.get(); + let mut camera_mapper = ui_camera_map.get_mapper(); for (entity, block, content_size, text_flags, computed, maybe_camera) in &mut text_query { - let Some(camera_entity) = maybe_camera - .map(TargetCamera::entity) - .or(default_camera_entity) - else { + let Some(camera_entity) = camera_mapper.map(maybe_camera) else { continue; }; let scale_factor = match scale_factors_buffer.entry(camera_entity) { From 4a61d4a83a623f13ba044daa797f67df86831aec Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Thu, 16 Jan 2025 15:04:10 +0000 Subject: [PATCH 13/18] Fixed imports --- crates/bevy_ui/src/widget/text.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 3dedfa491511e..915ba291e21d7 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -1,6 +1,6 @@ use crate::{ - ComputedNode, ContentSize, DefaultUiCamera, FixedMeasure, Measure, MeasureArgs, Node, - NodeMeasure, TargetCamera, UiCameraMap, UiScale, + ComputedNode, ContentSize, FixedMeasure, Measure, MeasureArgs, Node, NodeMeasure, TargetCamera, + UiCameraMap, UiScale, }; use bevy_asset::Assets; use bevy_color::Color; From 6cb83c9b9530e15b7dc9dbf07deb09c427c2834f Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 22 Jan 2025 15:20:57 +0000 Subject: [PATCH 14/18] Fixed errors from merge --- crates/bevy_ui/src/render/box_shadow.rs | 2 +- crates/bevy_ui/src/render/debug_overlay.rs | 1 + crates/bevy_ui/src/render/mod.rs | 9 ++++----- crates/bevy_ui/src/widget/text.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/bevy_ui/src/render/box_shadow.rs b/crates/bevy_ui/src/render/box_shadow.rs index 0ce876619296d..07b99cfed2d10 100644 --- a/crates/bevy_ui/src/render/box_shadow.rs +++ b/crates/bevy_ui/src/render/box_shadow.rs @@ -3,7 +3,7 @@ use core::{hash::Hash, ops::Range}; use crate::{ - BoxShadow, BoxShadowSamples, CalculatedClip, ComputedNode, DefaultUiCamera, RenderUiSystem, + BoxShadow, BoxShadowSamples, CalculatedClip, ComputedNode, RenderUiSystem, ResolvedBorderRadius, TransparentUi, UiTargetCamera, Val, }; use bevy_app::prelude::*; diff --git a/crates/bevy_ui/src/render/debug_overlay.rs b/crates/bevy_ui/src/render/debug_overlay.rs index 86289c6efc856..460875f8819bd 100644 --- a/crates/bevy_ui/src/render/debug_overlay.rs +++ b/crates/bevy_ui/src/render/debug_overlay.rs @@ -1,6 +1,7 @@ use crate::CalculatedClip; use crate::ComputedNode; use crate::UiTargetCamera; +use bevy_asset::AssetId; use bevy_color::Hsla; use bevy_ecs::entity::Entity; use bevy_ecs::resource::Resource; diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 2ba5bc18a6f0e..79d8333e81e3f 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -7,6 +7,7 @@ pub mod ui_texture_slice_pipeline; #[cfg(feature = "bevy_ui_debug")] mod debug_overlay; +use crate::experimental::UiChildren; use crate::widget::ImageNode; use crate::{ BackgroundColor, BorderColor, BoxShadowSamples, CalculatedClip, ComputedNode, DefaultUiCamera, @@ -279,10 +280,10 @@ pub struct UiCameraMapper<'w, 's> { } impl<'w, 's> UiCameraMapper<'w, 's> { - /// Returns the render entity corresponding to the given `TargetCamera` or the default camera if `None`. - pub fn map(&mut self, camera: Option<&TargetCamera>) -> Option { + /// Returns the render entity corresponding to the given `UiTargetCamera` or the default camera if `None`. + pub fn map(&mut self, camera: Option<&UiTargetCamera>) -> Option { let camera_entity = camera - .map(TargetCamera::entity) + .map(UiTargetCamera::entity) .or(self.default_camera_entity)?; if self.camera_entity != camera_entity { @@ -483,8 +484,6 @@ pub fn extract_uinode_borders( AnyOf<(&BorderColor, &Outline)>, )>, >, - parent_clip_query: Extract>, - ui_children: UiChildren, camera_map: Extract, ) { let image = AssetId::::default(); diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 9deb90db1fcd9..b695a8e6ab4ef 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -1,6 +1,6 @@ use crate::{ - ComputedNode, ContentSize, FixedMeasure, Measure, MeasureArgs, Node, NodeMeasure, UiScale, - UiTargetCamera, + ComputedNode, ContentSize, FixedMeasure, Measure, MeasureArgs, Node, NodeMeasure, UiCameraMap, + UiScale, UiTargetCamera, }; use bevy_asset::Assets; use bevy_color::Color; From 864b1bb83bf70d171a3653411d86aac0ead4b1d3 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 22 Jan 2025 15:22:13 +0000 Subject: [PATCH 15/18] Fixed another import --- crates/bevy_ui/src/render/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 79d8333e81e3f..32c8605729e29 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -7,7 +7,6 @@ pub mod ui_texture_slice_pipeline; #[cfg(feature = "bevy_ui_debug")] mod debug_overlay; -use crate::experimental::UiChildren; use crate::widget::ImageNode; use crate::{ BackgroundColor, BorderColor, BoxShadowSamples, CalculatedClip, ComputedNode, DefaultUiCamera, From de967ee5def19b223987356a8089abb05b5ced57 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 22 Jan 2025 15:57:11 +0000 Subject: [PATCH 16/18] Fixed text scalefactor --- crates/bevy_ui/src/render/mod.rs | 1 - crates/bevy_ui/src/widget/text.rs | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 32c8605729e29..022031e31df50 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -284,7 +284,6 @@ impl<'w, 's> UiCameraMapper<'w, 's> { let camera_entity = camera .map(UiTargetCamera::entity) .or(self.default_camera_entity)?; - if self.camera_entity != camera_entity { let Ok(new_render_camera_entity) = self.mapping.get(camera_entity) else { return None; diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index b695a8e6ab4ef..e9694f62b63e2 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -1,6 +1,6 @@ use crate::{ - ComputedNode, ContentSize, FixedMeasure, Measure, MeasureArgs, Node, NodeMeasure, UiCameraMap, - UiScale, UiTargetCamera, + ComputedNode, ContentSize, DefaultUiCamera, FixedMeasure, Measure, MeasureArgs, Node, + NodeMeasure, UiScale, UiTargetCamera, }; use bevy_asset::Assets; use bevy_color::Color; @@ -245,7 +245,8 @@ pub fn measure_text_system( mut scale_factors_buffer: Local>, mut last_scale_factors: Local>, fonts: Res>, - camera_query: Query<(Entity, &Camera)>, + camera_query: Query<&Camera>, + default_ui_camera: DefaultUiCamera, ui_scale: Res, mut text_query: Query< ( @@ -261,27 +262,31 @@ pub fn measure_text_system( mut text_reader: TextUiReader, mut text_pipeline: ResMut, mut font_system: ResMut, - ui_camera_map: UiCameraMap, ) { scale_factors_buffer.clear(); - let mut camera_mapper = ui_camera_map.get_mapper(); + let default_camera_entity = default_ui_camera.get(); for (entity, block, content_size, text_flags, computed, maybe_camera) in &mut text_query { - let Some(camera_entity) = camera_mapper.map(maybe_camera) else { + let Some(camera_entity) = maybe_camera + .map(UiTargetCamera::entity) + .or(default_camera_entity) + else { continue; }; + let scale_factor = match scale_factors_buffer.entry(camera_entity) { Entry::Occupied(entry) => *entry.get(), Entry::Vacant(entry) => *entry.insert( camera_query .get(camera_entity) .ok() - .and_then(|(_, c)| c.target_scaling_factor()) + .and_then(|c| c.target_scaling_factor()) .unwrap_or(1.0) * ui_scale.0, ), }; + println!("scale factor = {scale_factor}"); // Note: the ComputedTextBlock::needs_rerender bool is cleared in create_text_measure(). if last_scale_factors.get(&camera_entity) != Some(&scale_factor) || computed.needs_rerender() From 11fd6c7bba81fbdc946d22376647579390dccce3 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 22 Jan 2025 16:00:56 +0000 Subject: [PATCH 17/18] Removed debug print --- crates/bevy_ui/src/widget/text.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index e9694f62b63e2..4b53a875cf321 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -286,7 +286,7 @@ pub fn measure_text_system( * ui_scale.0, ), }; - println!("scale factor = {scale_factor}"); + // Note: the ComputedTextBlock::needs_rerender bool is cleared in create_text_measure(). if last_scale_factors.get(&camera_entity) != Some(&scale_factor) || computed.needs_rerender() From 398f3fa69e106abe4167a28b56fc00b9a3200ab9 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 22 Jan 2025 16:06:23 +0000 Subject: [PATCH 18/18] Removed redundant closure --- crates/bevy_ui/src/widget/text.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 4b53a875cf321..7e75d181955ab 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -281,7 +281,7 @@ pub fn measure_text_system( camera_query .get(camera_entity) .ok() - .and_then(|c| c.target_scaling_factor()) + .and_then(Camera::target_scaling_factor) .unwrap_or(1.0) * ui_scale.0, ),