From 92f39354a3fd7fb51ab6e0668f1522d3f5932614 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Sat, 5 Oct 2024 23:48:57 +0100 Subject: [PATCH] Display the bounds of each text node in the `text_debug` ui example (#15622) # Objective Add a background colour to each text node in the `text_debug` example to visualize their bounds. ## Showcase deb In the bottom right you can see the empty space at the bottom of the text node, making it much more obvious that there is a bug causing the size of the bounds to be calculated incorrectly. --- examples/ui/text_debug.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/ui/text_debug.rs b/examples/ui/text_debug.rs index 47b0b4121259e..d38e0b1265ec4 100644 --- a/examples/ui/text_debug.rs +++ b/examples/ui/text_debug.rs @@ -31,7 +31,9 @@ struct TextChanges; fn infotext_system(mut commands: Commands, asset_server: Res) { let font = asset_server.load("fonts/FiraSans-Bold.ttf"); + let background_color = MAROON.into(); commands.spawn(Camera2d); + let root_uinode = commands .spawn(NodeBundle { style: Style { @@ -64,6 +66,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { ..default() }, ) + .with_background_color(background_color) ); builder.spawn(TextBundle::from_section( "This text is right-justified. The `JustifyText` component controls the horizontal alignment of the lines of multi-line text relative to each other, and does not affect the text node's position in the UI layout.", TextStyle { @@ -77,6 +80,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { max_width: Val::Px(300.), ..default() }) + .with_background_color(background_color) ); builder.spawn( TextBundle::from_section( @@ -91,6 +95,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { max_width: Val::Px(300.), ..default() }) + .with_background_color(background_color) ); }).id(); @@ -119,6 +124,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { max_width: Val::Px(400.), ..default() }) + .with_background_color(background_color) ); builder.spawn( @@ -134,7 +140,8 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { .with_style(Style { max_width: Val::Px(300.), ..default() - }), + }) + .with_background_color(background_color) ); builder.spawn( @@ -150,7 +157,8 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { .with_style(Style { max_width: Val::Px(300.), ..default() - }), + }) + .with_background_color(background_color) ); builder.spawn(( @@ -221,12 +229,11 @@ fn infotext_system(mut commands: Commands, asset_server: Res) { color: BLUE.into(), }, ), - ]), + ]).with_background_color(background_color), TextChanges, )); }) .id(); - commands .entity(root_uinode) .add_children(&[left_column, right_column]);