Skip to content

bad size calculation for wrapping nodes (text or flex_wrap: Wrap) #16304

@robtfm

Description

@robtfm

Bevy version

0.15.0-rc.3

What you did

render a bit of text with the following code.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

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

    commands.spawn(Node::default()).with_children(|c| {
        c.spawn((Node {
            flex_direction: FlexDirection::Column,
            width: Val::Px(500.0),
            ..Default::default()
        },))
            .with_children(|c| {
                c.spawn((
                    Node {
                        min_width: Val::Px(500.0), // changing this to 499.999 works as expected
                        ..Default::default()
                    },
                    BackgroundColor::from(Color::srgba(0.0, 0.0, 1.0, 1.0)),
                ))
                .with_children(|c| {
                    c.spawn((Text::new("Some text and some more text"), ZIndex(1)));
                });
            });
    });
}

What went wrong

the text container is much too large vertically.

Image

Additional info

  • changing the min_width of the 3rd node to 499.999 or smaller sizes the text correctly (so maybe a propagation problem in taffy)
  • making the text shorter makes the oversize decrease, making it longer makes it increase (so maybe a text measure problem)
  • this was also an issue in 0.14.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-TextRendering and layout for charactersA-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorS-BlockedThis cannot move forward until something else changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions