From 91d5bc65a76f4741418204505f24a9b3383214d2 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 11 Aug 2025 21:25:58 +0100 Subject: [PATCH 1/2] Improved docs for for `UiCameraMap` and `UiCameraMapper`. --- crates/bevy_ui_render/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui_render/src/lib.rs b/crates/bevy_ui_render/src/lib.rs index 068335645d082..9493b220615cc 100644 --- a/crates/bevy_ui_render/src/lib.rs +++ b/crates/bevy_ui_render/src/lib.rs @@ -309,7 +309,9 @@ pub struct UiCameraMap<'w, 's> { } impl<'w, 's> UiCameraMap<'w, 's> { - /// Get the default camera and create the mapper + /// Creates a [`UiCameraMapper`] for performing repeated camera-to-render-entity lookups. + /// + /// The last successful mapping is cached to avoid redundant queries. pub fn get_mapper(&'w self) -> UiCameraMapper<'w, 's> { UiCameraMapper { mapping: &self.mapping, @@ -319,14 +321,18 @@ impl<'w, 's> UiCameraMap<'w, 's> { } } +/// Helper for mapping UI target camera entities to their corresponding render entities, +/// with caching to avoid repeated lookups for the same camera. pub struct UiCameraMapper<'w, 's> { mapping: &'w Query<'w, 's, RenderEntity>, + /// Cached camera entity from the last successful `map` call. camera_entity: Entity, + /// Cached camera entity from the last successful `map` call. render_entity: Entity, } impl<'w, 's> UiCameraMapper<'w, 's> { - /// Returns the render entity corresponding to the given `UiTargetCamera` or the default camera if `None`. + /// Returns the render entity corresponding to the given [`ComputedNodeTarget`]'s camera, or none if no corresponding entity was found. pub fn map(&mut self, computed_target: &ComputedNodeTarget) -> Option { let camera_entity = computed_target.camera()?; if self.camera_entity != camera_entity { @@ -338,6 +344,7 @@ impl<'w, 's> UiCameraMapper<'w, 's> { Some(self.render_entity) } + /// Returns the cached camera entity from the last successful `map` call. pub fn current_camera(&self) -> Entity { self.camera_entity } From 82bee42079b18b7a8a204a03a4c57acfe3ffd7d6 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 12 Aug 2025 07:45:00 +0100 Subject: [PATCH 2/2] Fixed doc link --- crates/bevy_ui_render/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui_render/src/lib.rs b/crates/bevy_ui_render/src/lib.rs index 912c33d72136d..f6a4524240ab4 100644 --- a/crates/bevy_ui_render/src/lib.rs +++ b/crates/bevy_ui_render/src/lib.rs @@ -324,7 +324,7 @@ pub struct UiCameraMapper<'w, 's> { } impl<'w, 's> UiCameraMapper<'w, 's> { - /// Returns the render entity corresponding to the given [`ComputedUiCameraTarget`]'s camera, or none if no corresponding entity was found. + /// Returns the render entity corresponding to the given [`ComputedUiTargetCamera`]'s camera, or none if no corresponding entity was found. pub fn map(&mut self, computed_target: &ComputedUiTargetCamera) -> Option { let camera_entity = computed_target.camera()?; if self.camera_entity != camera_entity {