Skip to content

Text2d and TextSpan is not center-aligned when JustifyText::Center is specified. #16783

@Ramirisu

Description

@Ramirisu

Bevy version

0.15

What went wrong

In bevy 0.14, the text sections correctly reflect the JustifyText::Center parameter, texts are center-aligned:

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

    commands.spawn(Text2dBundle {
        text: Text::from_sections([
                        TextSection {
                value: "Text Justification\n".into(),
                style: TextStyle {
                    color: WHITE.into(),
                    ..default()
                },
                ..default()
            },
            TextSection {
                value: "Center\n".into(),
                style: TextStyle {
                    color: YELLOW.into(),
                    ..default()
                },
                ..default()
            },
            TextSection {
                value: "xxxxxxxxxxCenterxxxxxxxxxx".into(),
                style: TextStyle {
                    color: RED.into(),
                    ..default()
                },
                ..default()
            },
        ])
        .with_justify(JustifyText::Center),
        transform: Transform::from_translation(Vec3::default()),
        ..default()
    });
}

Image

However, after upgrading to bevy 0.15, the Text2d and TextSpan are always left-aligned even though the TextLayout::new_with_justify(JustifyText::Center) is specified:

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

    commands
        .spawn((
            Text2d::new("Text Justification\n"),
            TextLayout::new_with_justify(JustifyText::Center),
            TextColor::from(WHITE),
            Transform::from_translation(Vec3::default()),
        ))
        .with_children(|parent| {
            parent.spawn((TextSpan::new("Center\n"), TextColor::from(YELLOW)));
            parent.spawn((
                TextSpan::new("xxxxxxxxxxCenterxxxxxxxxxx"),
                TextColor::from(RED),
            ));
        });
}

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorP-RegressionFunctionality that used to work but no longer does. Add a test for this!S-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions