diff --git a/crates/bevy_dev_tools/src/picking_debug.rs b/crates/bevy_dev_tools/src/picking_debug.rs index 8e4ee7ae86..79c1c8fff4 100644 --- a/crates/bevy_dev_tools/src/picking_debug.rs +++ b/crates/bevy_dev_tools/src/picking_debug.rs @@ -1,7 +1,6 @@ //! Text and on-screen debugging tools use bevy_app::prelude::*; -use bevy_asset::prelude::*; use bevy_color::prelude::*; use bevy_ecs::prelude::*; use bevy_picking::backend::HitData; @@ -248,25 +247,18 @@ pub fn debug_draw( pointers: Query<(Entity, &PointerId, &PointerDebug)>, scale: Res, ) { - let font_handle: Handle = Default::default(); - for (entity, id, debug) in pointers.iter() { + for (entity, id, debug) in &pointers { let Some(pointer_location) = &debug.location else { continue; }; let text = format!("{id:?}\n{debug}"); - for camera in camera_query - .iter() - .map(|(entity, camera)| { - ( - entity, - camera.target.normalize(primary_window.single().ok()), - ) - }) - .filter_map(|(entity, target)| Some(entity).zip(target)) - .filter(|(_entity, target)| target == &pointer_location.target) - .map(|(cam_entity, _target)| cam_entity) - { + for (camera, _) in camera_query.iter().filter(|(_, camera)| { + camera + .target + .normalize(primary_window.single().ok()) + .is_some_and(|target| target == pointer_location.target) + }) { let mut pointer_pos = pointer_location.position; if let Some(viewport) = camera_query .get(camera) @@ -278,23 +270,21 @@ pub fn debug_draw( commands .entity(entity) + .despawn_related::() .insert(( - Text::new(text.clone()), - TextFont { - font: font_handle.clone(), - font_size: 12.0, - ..Default::default() - }, - TextColor(Color::WHITE), Node { position_type: PositionType::Absolute, left: Val::Px(pointer_pos.x + 5.0) / scale.0, top: Val::Px(pointer_pos.y + 5.0) / scale.0, + padding: UiRect::px(10.0, 10.0, 8.0, 6.0), ..Default::default() }, - )) - .insert(Pickable::IGNORE) - .insert(UiTargetCamera(camera)); + BackgroundColor(Color::BLACK.with_alpha(0.75)), + GlobalZIndex(i32::MAX), + Pickable::IGNORE, + UiTargetCamera(camera), + children![(Text::new(text.clone()), TextFont::from_font_size(12.0))], + )); } } }