Skip to content

TextColor issue with TextSpan #20834

@gwafotapa

Description

@gwafotapa

The issue appeared with commit afc721e on the main branch.

Since that commit, the colors of a text block built of TextSpan nodes is messed up. The TextColor of the parent (with Text) is correct. But each TextSpan child uses the previous TextColor component instead of its own, i.e. the first child uses the TextColor of the parent, the second child that of the first and so on.

Here's a minimal example if you want to reproduce the issue.

use bevy::prelude::*;

fn main() {
    let mut app = App::new();
    app.add_plugins(DefaultPlugins)
        .add_systems(Startup, spawn_text)
        .run();
}

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

    commands.spawn((
        Text::new("B"),
        TextColor(Srgba::WHITE.into()),
        children![
            (TextSpan::new("e"), TextColor(Srgba::RED.into())),
            (TextSpan::new("v"), TextColor(Srgba::GREEN.into())),
            (TextSpan::new("y"), TextColor(Srgba::BLUE.into()))
        ],
    ));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenA-TextRendering and layout for charactersC-BugAn unexpected or incorrect behaviorS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions