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

TextAlignment has no effect on text alignment, only controls justification for multi-line texts #8659

Closed
djeedai opened this issue May 23, 2023 · 3 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use

Comments

@djeedai
Copy link
Contributor

djeedai commented May 23, 2023

Unlike CSS text-align which aligns the text inside a box and justify it, in Bevy the alignment of text is based on the concept of anchors. One can build a similar result to CSS text-align based on anchors and a parent node, but by default the anchor itself does the alignment.

The TextAlignment property actually controls the justifying of multi-line text only.

  • It has no effect on single-line text, which is a major difference with CSS
  • For multi-line texts, it aligns all-but-the-longest lines inside the horizontal space defined by the longest line.

It's arguable the name TextAlignment is suited, due to confusion with CSS and general meaning of "align" which for UI actually move elements to the left/right, whereas here the text as a whole never moves (some parts of it do, but the bounds are unaffected).

To make things more confusing, the documentation talks about changes to bounds, but text alignment has no effect on the text bounds, sine all "alignment" is done within the computed bounds derived from the max line length and number of lines.

Proposed actions

  • A minima, fix docs to not talk about bounds
  • Call out the major difference with CSS text-align
  • I'd personally be for a rename of that type to avoid confusion.
@djeedai djeedai added C-Docs An addition or correction to our documentation A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use labels May 23, 2023
@ickshonpe
Copy link
Contributor

ickshonpe commented May 23, 2023

To clarify, are we talking about Text2d or text in the UI? Only the Text2d implementation uses anchors but it has nothing to do with CSS. It's mostly used for drawing floating text above sprites etc, and it uses anchors to be consistent with the sprite API.

TextAlignment was renamed from HorizontalAlign (or something, there also used to be a VerticalAlign enum) back in 0.9 and I must have overlooked the doc comments when I made those changes. They are definitely incorrect and need to be changed. I think probably some sort of diagram would be useful too.

@djeedai
Copy link
Contributor Author

djeedai commented May 27, 2023

To clarify, are we talking about Text2d or text in the UI?

I tested with Text2dBundle. Although that's part of the issue: I'm well unable to tell what "text in the UI" is and how it's different from Text2d. We shouldn't have multiple text behaviors.

@rparrett
Copy link
Contributor

I believe this was fixed by #10854. Please reopen if I'm wrong.

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-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants