Skip to content

Commit

Permalink
Display the bounds of each text node in the text_debug ui example (#…
Browse files Browse the repository at this point in the history
…15622)

# Objective

Add a background colour to each text node in the `text_debug` example to
visualize their bounds.

## Showcase

<img width="961" alt="deb"
src="https://github.com/user-attachments/assets/deec3e15-b0f0-411f-9af1-597587ac2a83">

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.
  • Loading branch information
ickshonpe authored Oct 5, 2024
1 parent 0b5a360 commit 92f3935
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions examples/ui/text_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ struct TextChanges;

fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
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 {
Expand Down Expand Up @@ -64,6 +66,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
..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 {
Expand All @@ -77,6 +80,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
max_width: Val::Px(300.),
..default()
})
.with_background_color(background_color)
);
builder.spawn(
TextBundle::from_section(
Expand All @@ -91,6 +95,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
max_width: Val::Px(300.),
..default()
})
.with_background_color(background_color)
);
}).id();

Expand Down Expand Up @@ -119,6 +124,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
max_width: Val::Px(400.),
..default()
})
.with_background_color(background_color)
);

builder.spawn(
Expand All @@ -134,7 +140,8 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
.with_style(Style {
max_width: Val::Px(300.),
..default()
}),
})
.with_background_color(background_color)
);

builder.spawn(
Expand All @@ -150,7 +157,8 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
.with_style(Style {
max_width: Val::Px(300.),
..default()
}),
})
.with_background_color(background_color)
);

builder.spawn((
Expand Down Expand Up @@ -221,12 +229,11 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
color: BLUE.into(),
},
),
]),
]).with_background_color(background_color),
TextChanges,
));
})
.id();

commands
.entity(root_uinode)
.add_children(&[left_column, right_column]);
Expand Down

0 comments on commit 92f3935

Please sign in to comment.