Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoWrap Text feature #8947

Merged
merged 14 commits into from
Jun 26, 2023
Merged

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Jun 24, 2023

Objective

In Bevy 10.1 and before, the only way to enable text wrapping was to set a local Val::Px width constraint on the text node itself. Val::Percent constraints and constraints on the text node's ancestors did nothing.

#7779 fixed those problems. But perversely displaying unwrapped text is really difficult now, and requires users to nest each TextBundle in a NodeBundle and apply min_width and max_width constraints. Some constructions may even need more than one layer of nesting. I've seen several people already who have really struggled with this when porting their projects to main in advance of 0.11.

Solution

Add a NoWrap variant to the BreakLineOn enum.
If NoWrap is set, ignore any constraints on the width for the text and call TextPipeline::queue_text with a width bound of f32::INFINITY.


Changelog

  • Added a NoWrap variant to the BreakLineOn enum.
  • If NoWrap is set, any constraints on the width for the text are ignored and TextPipeline::queue_text is called with a width bound of f32::INFINITY.
  • Changed the size field of FixedMeasure to pub. This shouldn't have been private, it was always intended to have pub visibility.
  • Added a with_no_wrap method to TextBundle.

Migration Guide

bevy_text::text::BreakLineOn has a new variant NoWrap that disables text wrapping for the Text.
Text wrapping can also be disabled using the with_no_wrap method of TextBundle.

The `size` field is changed to public. It shouldn't have been private, this was an error.

`TextWrapOverride`
Enum that describes alternative text wrapping behaviours.

`TextOptions`
Component with extra options for Bevy UI's `TextBundle` that aren't needed for `Text2dBundle`.

`Text2dBundle`
Added `TextOptions` component to this bundle.
Instead a variant `NeverBreak` has been added to the `BreakLineOn` enum.
Added `Text2d` support for the `NoWrap` variant by setting the width bound to infinity if `NoWrap` is set.

`BreakLineOn::NeverBreak` renamed to `BreakLineOn::NoWrap` to match the name of the CSS text property `no_wrap`.

`text_wrap_debug`
Set `Oveflow::clip_x()` on each of the panels, to clip the unwrapped text.
Removed a line intializing the style to default for a `TextBundle` that did nothing.
@ickshonpe ickshonpe changed the title Add an option to disable text wrapping NoWrap Text option Jun 24, 2023
@ickshonpe ickshonpe changed the title NoWrap Text option NoWrap Text feature Jun 24, 2023
@mockersf mockersf added the A-UI Graphical user interfaces, styles, layouts, and widgets label Jun 24, 2023
Copy link
Contributor

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style/documentation changes requested, but the meat of the implementation looks good to me.

crates/bevy_text/src/text.rs Outdated Show resolved Hide resolved
crates/bevy_ui/src/widget/text.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the C-Usability A simple quality-of-life change that makes Bevy easier to use label Jun 25, 2023
@alice-i-cecile alice-i-cecile added this to the 0.11 milestone Jun 25, 2023
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 25, 2023
Corrected a mistake in the description for `NoWrap`.

Added more detailed comments explaining that `NoWrap` only disables soft wrapping and that hard wrapping will still occur.
Copy link
Contributor

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My nits have now been addressed, so I think this is good to go :)

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 26, 2023
Merged via the queue into bevyengine:main with commit aeea4b0 Jun 26, 2023
40 checks passed
@Selene-Amanita Selene-Amanita added the C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide label Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants