From 079b5aa787236134dd5903f6fed5822b6a706934 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 5 Aug 2025 11:11:39 -0700 Subject: [PATCH] Tooltip in world space works, need to populate with data --- src/debug.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/debug.rs b/src/debug.rs index 0b0faa0..e7dd050 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -36,7 +36,9 @@ impl Plugin for DebuggingPlugin { ) .run_if(in_state(DebuggingState::On)), ), - ); + ) + .add_observer(add_tooltip_text) + .add_observer(remove_tooltip_text); // WebGL2-incompatible systems #[cfg(not(target_arch = "wasm32"))] @@ -265,6 +267,37 @@ fn lock_tooltip( }); } +/// when a tooltip is added to an entity, insert the text component +fn add_tooltip_text( + trigger: Trigger, + mut commands: Commands, +) { + info!("Adding text2d to {:?}", trigger.target()); + commands.entity(trigger.target()).with_children(|parent| { + parent.spawn(( + TextColor(GREEN.into()), + Text2d("Placeholder".into()), + Transform::from_xyz(1.5, 0.0, 1.0).with_scale(Vec3::splat(0.01)), + )); + }); +} + +/// when a tooltip is removed to an entity, remove the text components +fn remove_tooltip_text( + trigger: Trigger, + mut commands: Commands, + parents: Query<&Children>, + text_2d: Query>, +) { + // Get lis of children for this entity + let children = parents.get(trigger.target()).unwrap(); + // Find the tooltip text child + if let Some(child) = children.iter().find_map(|child| text_2d.get(child).ok()) { + // Remove it from the world + commands.entity(child).despawn(); + } +} + /// When you hover over a mesh, update the tooltip with some info fn hover_mesh( mut over_events: EventReader>,