bevyengine / bevyengine/bevy

LineBreak Text Wrapping does not work reliably

Open
#17,437 0 comments 0 reactions 0 assignees View on GitHub
A-Text C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.15.1


## What you did

So i have a root container node (container_node) that has the following Node props :

```
width: Val::Px(200.0),

display: Display::Flex,
flex_direction: FlexDirection::Column, // Set direction to column for vertical layout
justify_content: JustifyContent::FlexStart, // Adjust main axis distribution as needed
align_items: AlignItems::FlexStart, // Adjust cross axis alignment (center, flex-end, etc.)

```

Now I attach a container to it which has a Node parent and a Text child.

When I make the width of that inner Node (the direct parent of the Text) be Val::Percent(100.0), the rendering system properly renders that node as being 200.0 pixels width because it gets it relative to its parent. However, after much experimentation , it seems to me that the Text system word wrapping is breaking from this and it not detecting that the rendered (inherited) width of its parent is 200 pixels.

```
commands.ui_builder( container_node )
.container( Node {
padding: UiRect::vertical(Val::Px(2.0)) ,


width: Val::Percent(100.0), // this DOES NOT work

min_width: Val::Px(0.0) ,

..default()
}, |inner| {
inner .spawn((
Text::new("".to_string()),
TextFont::from_font_size(9.0),
TextColor( UiColorPresets::Gray.into() ),
TextLayout::new(JustifyText::Left, LineBreak::WordBoundary), // italics ?
TooltipDescription,
)) ;
});

```

## What went wrong
With the above code, even though the Node with width of 100% is rendering at 200px, the text acts like it is within a box that has is the entire width of the entire screen ; it doesnt wrap.

I can only make the text wrap if i make its immediate parent have an Explicit pixel-amount width. not a percent width.

Furthermore, it seems like giving that immediate parent a min_ and max_width doesnt help at all. word wrapping only seems to work if the immediate parent has a defined width that is actually constraining itself . If the immediates parents width is constrained by the node tree above it (inheriting a width) word wrapping isnt working for me .

## More Info

Here is a test case that shows the problem

https://learnbevy.com/playground?share=5962b421018b6c78208dfb34a09464a7f9f58b3cd1f25c492f1592c1cc49f0c7

The problem mostly seems to occur when i add

```
display: Display::Flex,
flex_direction: FlexDirection::Column, // Set direction to column for vertical layout
justify_content: JustifyContent::FlexStart, // Adjust main axis distribution as needed
align_items: AlignItems::FlexStart, // Adjust cross axis alignment (center, flex-end, etc.)

```
To the outer container node. But why would that cause the issue !?

Contributor guide

Open the contributing guide

Research direction

Start with the linked playground reproduction and compare the outer flex container, the percent-width inner Node, and the Text using LineBreak::WordBoundary. Investigate how the rendered inherited width reaches text layout, then verify that percent-constrained parents wrap text like the equivalent explicit pixel width.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.