Made the debug UI look a little less awful

main
Elijah Voigt 3 months ago
parent d33460a884
commit c24dabde16

@ -33,7 +33,7 @@ fn setup_list(mut commands: Commands) {
..default() ..default()
},)) },))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("This srolls".into())); parent.spawn(Text("This scrolls...".into()));
// List items // List items
(0..250).for_each(|i| { (0..250).for_each(|i| {
parent.spawn(Text(format!("Item {i}"))); parent.spawn(Text(format!("Item {i}")));
@ -60,7 +60,7 @@ fn setup_nav_tree(mut commands: Commands) {
commands commands
.spawn(( .spawn((
Node { Node {
align_self: AlignSelf::Start, top: Val::Percent(25.0),
justify_self: JustifySelf::End, justify_self: JustifySelf::End,
min_width: Val::Px(25.0), min_width: Val::Px(25.0),
min_height: Val::Px(25.0), min_height: Val::Px(25.0),
@ -80,12 +80,11 @@ fn setup_nav_tree(mut commands: Commands) {
position_type: PositionType::Absolute, position_type: PositionType::Absolute,
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
right: Val::Percent(100.0), right: Val::Percent(100.0),
width: Val::Auto,
..default() ..default()
}, },
)) ))
.with_children(|parent| { .with_children(|parent| {
(0..10).for_each(|_| { (0..5).for_each(|_| {
let title: String = lipsum_title_with_rng(thread_rng()) let title: String = lipsum_title_with_rng(thread_rng())
.split_whitespace() .split_whitespace()
.take(2) .take(2)

@ -71,10 +71,10 @@ fn init_debug_ui(mut commands: Commands) {
commands.spawn(( commands.spawn((
DebuggingState::On, DebuggingState::On,
Name::new("Debug Indicator"), Name::new("Debug Indicator"),
Text(" Debug: ON ".into()), GlobalZIndex(i32::MAX - 1),
TextColor(WHITE.into()), children![
BackgroundColor(RED.into()), Text(" Debug: ON ".into()),
BorderRadius::MAX, ],
Node { Node {
align_self: AlignSelf::Center, align_self: AlignSelf::Center,
justify_self: JustifySelf::End, justify_self: JustifySelf::End,
@ -86,9 +86,10 @@ fn init_debug_ui(mut commands: Commands) {
commands.spawn(( commands.spawn((
DebuggingState::On, DebuggingState::On,
Name::new("Version #"), Name::new("Version #"),
Text::new(VERSION), children![
TextColor(WHITE.into()), Text::new(VERSION),
BackgroundColor(BLACK.into()), ],
GlobalZIndex(i32::MAX - 1),
Node { Node {
width: Val::Auto, width: Val::Auto,
align_self: AlignSelf::End, align_self: AlignSelf::End,
@ -101,41 +102,42 @@ fn init_debug_ui(mut commands: Commands) {
commands.spawn(( commands.spawn((
DebuggingState::On, DebuggingState::On,
Name::new("FPS"), Name::new("FPS"),
Text::new("FPS: ##.#"), GlobalZIndex(i32::MAX - 1),
TextColor(WHITE.into()),
BackgroundColor(BLACK.into()),
SyncResource::<Fps>::default(),
Node { Node {
width: Val::Auto, width: Val::Auto,
align_self: AlignSelf::Start, align_self: AlignSelf::Start,
justify_self: JustifySelf::End, justify_self: JustifySelf::End,
..default() ..default()
}, },
)); )).with_children(|parent| {
parent.spawn((
Text::new("FPS: ##.#"),
SyncResource::<Fps>::default(),
));
});
commands.spawn(( commands.spawn((
DebuggingState::On, DebuggingState::On,
Name::new("Entity Count"), Name::new("Entity Count"),
Text::new("Entities: ###"), GlobalZIndex(i32::MAX - 1),
TextColor(WHITE.into()),
BackgroundColor(BLACK.into()),
SyncResource::<EntityCount>::default(),
Node { Node {
width: Val::Auto, width: Val::Auto,
align_self: AlignSelf::Start, align_self: AlignSelf::Start,
justify_self: JustifySelf::Center, justify_self: JustifySelf::Center,
..default() ..default()
}, },
)); )).with_children(|parent| {
parent.spawn((
Text::new("Entities: ###"),
SyncResource::<EntityCount>::default(),
));
});
// Tooltip // Tooltip
commands.spawn(( commands.spawn((
DebuggingState::On, DebuggingState::On,
Text("Tooltip Placeholder".into()),
Pickable::IGNORE,
TextColor(WHITE.into()),
SyncResource::<ToolTip>::default(), SyncResource::<ToolTip>::default(),
BackgroundColor(BLACK.with_alpha(0.9).into()), Pickable::IGNORE,
GlobalZIndex(i32::MAX), GlobalZIndex(i32::MAX),
Node { Node {
position_type: PositionType::Absolute, position_type: PositionType::Absolute,
@ -147,7 +149,12 @@ fn init_debug_ui(mut commands: Commands) {
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
..default() ..default()
}, },
)); )).with_children(|parent| {
parent.spawn((
Text("Tooltip Placeholder".into()),
SyncResource::<ToolTip>::default(),
));
});
} }
/// Toggles the debug state from off -> on // off -> on when triggered /// Toggles the debug state from off -> on // off -> on when triggered
@ -197,7 +204,7 @@ impl Display for ToolTip {
} }
fn tooltip_follow( fn tooltip_follow(
mut tooltip: Single<(&mut Node, &mut Visibility), With<SyncResource<ToolTip>>>, mut tooltip: Single<(&mut Node, &mut Visibility), (With<SyncResource<ToolTip>>, Without<Text>)>,
window: Single<&Window>, window: Single<&Window>,
) { ) {
if let Some(Vec2 { x, y }) = window.cursor_position() { if let Some(Vec2 { x, y }) = window.cursor_position() {

@ -14,6 +14,7 @@ impl Plugin for BaseUiPlugin {
add_ui_text add_ui_text
.run_if(any_component_added::<Text>) .run_if(any_component_added::<Text>)
.after(add_ui_node), .after(add_ui_node),
navs_on_top.run_if(any_component_changed::<NavState>)
), ),
); );
} }
@ -98,11 +99,11 @@ fn add_ui_text(added: Query<Entity, Added<Text>>, mut commands: Commands) {
style: Res<Style>, style: Res<Style>,
) { ) {
// ONLY DO THIS IF CHILD OF BUTTON // ONLY DO THIS IF CHILD OF BUTTON
if let Ok((mut tc, ChildOf(p))) = query.get_mut(trigger.target()) { if let Ok((mut tc, ChildOf(p))) = query.get_mut(trigger.target())
if buttons.contains(*p) { && buttons.contains(*p)
debug!("pointer pressed {:?}", trigger.target()); {
tc.0 = style.primary; debug!("pointer pressed {:?}", trigger.target());
} tc.0 = style.primary;
} }
} }
@ -113,11 +114,11 @@ fn add_ui_text(added: Query<Entity, Added<Text>>, mut commands: Commands) {
style: Res<Style>, style: Res<Style>,
) { ) {
// ONLY DO THIS IF CHILD OF BUTTON // ONLY DO THIS IF CHILD OF BUTTON
if let Ok((mut tc, ChildOf(p))) = query.get_mut(trigger.target()) { if let Ok((mut tc, ChildOf(p))) = query.get_mut(trigger.target())
if buttons.contains(*p) { && buttons.contains(*p)
debug!("pointer released {:?}", trigger.target()); {
tc.0 = style.secondary; debug!("pointer released {:?}", trigger.target());
} tc.0 = style.secondary;
} }
} }
@ -137,10 +138,8 @@ fn add_ui_node(
added.iter_mut().for_each(|(e, mut n)| { added.iter_mut().for_each(|(e, mut n)| {
debug!("Updating node: {:?}", e); debug!("Updating node: {:?}", e);
n.padding = UiRect::all(Val::Px(3.0));
// Update Node border // Update Node border
n.border = UiRect::all(Val::Px(1.0)); n.border = UiRect::all(Val::Px(2.0));
let mut this = commands.entity(e); let mut this = commands.entity(e);
@ -208,3 +207,19 @@ pub enum NavState {
#[default] #[default]
Closed, Closed,
} }
fn navs_on_top(
changed: Query<(Entity, &NavState), Changed<NavState>>,
mut commands: Commands,
) {
changed.iter().for_each(|(e, ns)| {
match ns {
NavState::Open => {
commands.entity(e).insert(GlobalZIndex(i32::MAX/ 2));
}
NavState::Closed => {
commands.entity(e).remove::<GlobalZIndex>();
}
}
})
}

Loading…
Cancel
Save