Improve visibility of debug picking node (#18990)
# Objective Fixes https://github.com/bevyengine/bevy/issues/18989. ## Solution Add `GlobalZIndex(i32::MAX)`, `BackgroundColor(Color::BLACK.with_alpha(0.75))`, and some padding. ## Testing Ran `cargo run --example debug_picking`:  Before this PR: 
This commit is contained in:
parent
4924cf5828
commit
475b5a8557
@ -1,7 +1,6 @@
|
|||||||
//! Text and on-screen debugging tools
|
//! Text and on-screen debugging tools
|
||||||
|
|
||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
use bevy_asset::prelude::*;
|
|
||||||
use bevy_color::prelude::*;
|
use bevy_color::prelude::*;
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_picking::backend::HitData;
|
use bevy_picking::backend::HitData;
|
||||||
@ -248,25 +247,18 @@ pub fn debug_draw(
|
|||||||
pointers: Query<(Entity, &PointerId, &PointerDebug)>,
|
pointers: Query<(Entity, &PointerId, &PointerDebug)>,
|
||||||
scale: Res<UiScale>,
|
scale: Res<UiScale>,
|
||||||
) {
|
) {
|
||||||
let font_handle: Handle<Font> = Default::default();
|
for (entity, id, debug) in &pointers {
|
||||||
for (entity, id, debug) in pointers.iter() {
|
|
||||||
let Some(pointer_location) = &debug.location else {
|
let Some(pointer_location) = &debug.location else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let text = format!("{id:?}\n{debug}");
|
let text = format!("{id:?}\n{debug}");
|
||||||
|
|
||||||
for camera in camera_query
|
for (camera, _) in camera_query.iter().filter(|(_, camera)| {
|
||||||
.iter()
|
camera
|
||||||
.map(|(entity, camera)| {
|
.target
|
||||||
(
|
.normalize(primary_window.single().ok())
|
||||||
entity,
|
.is_some_and(|target| target == pointer_location.target)
|
||||||
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)
|
|
||||||
{
|
|
||||||
let mut pointer_pos = pointer_location.position;
|
let mut pointer_pos = pointer_location.position;
|
||||||
if let Some(viewport) = camera_query
|
if let Some(viewport) = camera_query
|
||||||
.get(camera)
|
.get(camera)
|
||||||
@ -278,23 +270,21 @@ pub fn debug_draw(
|
|||||||
|
|
||||||
commands
|
commands
|
||||||
.entity(entity)
|
.entity(entity)
|
||||||
|
.despawn_related::<Children>()
|
||||||
.insert((
|
.insert((
|
||||||
Text::new(text.clone()),
|
|
||||||
TextFont {
|
|
||||||
font: font_handle.clone(),
|
|
||||||
font_size: 12.0,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
TextColor(Color::WHITE),
|
|
||||||
Node {
|
Node {
|
||||||
position_type: PositionType::Absolute,
|
position_type: PositionType::Absolute,
|
||||||
left: Val::Px(pointer_pos.x + 5.0) / scale.0,
|
left: Val::Px(pointer_pos.x + 5.0) / scale.0,
|
||||||
top: Val::Px(pointer_pos.y + 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()
|
..Default::default()
|
||||||
},
|
},
|
||||||
))
|
BackgroundColor(Color::BLACK.with_alpha(0.75)),
|
||||||
.insert(Pickable::IGNORE)
|
GlobalZIndex(i32::MAX),
|
||||||
.insert(UiTargetCamera(camera));
|
Pickable::IGNORE,
|
||||||
|
UiTargetCamera(camera),
|
||||||
|
children![(Text::new(text.clone()), TextFont::from_font_size(12.0))],
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user