bevyengine / bevyengine/bevy

In TextLayout, when deleting all TextSpans, TextLayout still retains the last text

Open
#19,657 2 comments 0 reactions 0 assignees View on GitHub
A-UI C-Bug S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

v0.16.1 and current main

## What you did
When I wanted to make a small Text Input, I found that deleting all TextSpans would still keep the last character.

## What went wrong

When deleting all TextSpan, shouldn't it be blank?

## Additional information

Image

Image
When deleting all TextSpans, the last character will be left, white

```rust
use bevy::input::common_conditions::input_just_pressed;
use bevy::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
// .add_plugins(dev_tools::plugin)
.add_systems(Startup, setup)
.add_systems(
Update,
delete.run_if(input_just_pressed(KeyCode::Backspace)),
)
.run();
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2d);

commands.spawn((
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
BackgroundColor(Srgba::GREEN.into()),
children![(
Text::default(),
TextLayout::default(),
TextFont {
font_size: 60.0,
..Default::default()
},
TextColor(Srgba::BLACK.into()),
TextRoot,
children![
(
TextSpan::new("1"),
TextFont {
font_size: 60.0,
..Default::default()
},
TextColor(Srgba::BLACK.into()),
),
(
TextSpan::new("2"),
TextFont {
font_size: 60.0,
..Default::default()
},
TextColor(Srgba::BLACK.into()),
),
(
TextSpan::new("3"),
TextFont {
font_size: 60.0,
..Default::default()
},
TextColor(Srgba::BLACK.into()),
),
]
)],
));
}

fn delete(mut commands: Commands, texts: Single<&Children, With>) {
let children = texts.into_inner();
if let Some(t) = children.last() {
commands.entity(*t).despawn();
}
}

#[derive(Component, Reflect, Debug)]
#[reflect(Component)]
struct TextRoot;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.