-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Open
Labels
A-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
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


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<TextRoot>>) {
let children = texts.into_inner();
if let Some(t) = children.last() {
commands.entity(*t).despawn();
}
}
#[derive(Component, Reflect, Debug)]
#[reflect(Component)]
struct TextRoot;
Metadata
Metadata
Assignees
Labels
A-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!