Skip to content

GlyphLayout: justify text option(s)#7609

Merged
obigu merged 11 commits into
libgdx:masterfrom
StartsMercury:label-justify
Apr 4, 2026
Merged

GlyphLayout: justify text option(s)#7609
obigu merged 11 commits into
libgdx:masterfrom
StartsMercury:label-justify

Conversation

@StartsMercury

@StartsMercury StartsMercury commented Mar 16, 2025

Copy link
Copy Markdown
Contributor

Initial implementation of adding layout support on GlyphLayout for justified text.

Which lines to justify:

  • wrapped lines except last.
  • wrapped lines and last
  • all lines

How to expand:

  • only changing regular space glyphs
  • all glyphs will change to fill the width

Additional parameter on GlyphLayout.setText. Its previous signature remains, defaulting to use Justify.None.

Note: some constant names were changed, but the ordinals should still match.

@tommyettinger tommyettinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mostly looks good, but there's no documentation here and the new behavior will definitely need some kind of help provided to users if they are going to make use of this at all. I think Wrapping should just be 3 protected ints defined in GlyphLayout if it isn't meant to be used by the public, or a Wrapping enum if it is meant to be used by the public. Justify, its constants, and any public code that takes a Justify constant all really need documentation, even a little.

This seems like a really useful PR, and I'm willing to fill out or polish up documentation if you want, but I don't adequately understand what all the Justify constants do at this point.

Comment thread gdx/src/com/badlogic/gdx/utils/Wrapping.java Outdated
Comment thread gdx/src/com/badlogic/gdx/graphics/g2d/GlyphLayout.java
Comment thread gdx/src/com/badlogic/gdx/graphics/g2d/GlyphLayout.java
Comment thread gdx/src/com/badlogic/gdx/utils/Justify.java
tommyettinger
tommyettinger previously approved these changes Apr 13, 2025

@tommyettinger tommyettinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks much better! I have no qualms here with the PR, great work!

@NathanSweet

Copy link
Copy Markdown
Member

It looks well done!

I don't like setText having so many parameters, but what's one more at this point.

The impact on code paths that don't use justify seems minimal.

@StartsMercury Why are GlyphRun wrapState and the constants protected? If they are truly useful outside of GlyphLayout then public may be a better choice, with the constants as an enum. Everything else looks OK, I think we can merge after that question.

@StartsMercury

Copy link
Copy Markdown
Contributor Author

Why are GlyphRun wrapState and the constants protected? If they are truly useful outside of GlyphLayout then public may be a better choice, with the constants as an enum.

My thought was that it's currently internal to justify, though it is open to change to public. Users might find wrapState useful, thinking back now, so changing it (back) to public access may be a good idea. I do agree that the constants be an enum. Should a WrapState enum be contained in GlyphLayout, along with GlyphRun?

@NathanSweet

Copy link
Copy Markdown
Member

Yeah, I think it's good to put the enum in GlyphLayout.

@StartsMercury

StartsMercury commented Apr 26, 2025

Copy link
Copy Markdown
Contributor Author

I just noticed, should GlyphRun.wrapState be included in GlyphRun.toString()?

@NathanSweet

Copy link
Copy Markdown
Member

Sure, it could. The toString mainly for debugging.

@obigu obigu added this to the 1.14.1 milestone Oct 31, 2025
@obigu

obigu commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Except from maybe a line in CHANGES, can this be merged @NathanSweet ?

@NathanSweet

Copy link
Copy Markdown
Member

Yes, I think so. I hate making GlyphLayout even more complex and hope to never have to debug this, but it looks well done and doesn't add much overhead when not using justification.

@obigu obigu merged commit 72f31a0 into libgdx:master Apr 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants