X Tutup
Skip to content

GlyphLayout: justify text option(s)#7609

Open
StartsMercury wants to merge 9 commits intolibgdx:masterfrom
StartsMercury:label-justify
Open

GlyphLayout: justify text option(s)#7609
StartsMercury wants to merge 9 commits intolibgdx:masterfrom
StartsMercury:label-justify

Conversation

@StartsMercury
Copy link

@StartsMercury StartsMercury commented Mar 16, 2025

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.

Copy link
Member

@tommyettinger tommyettinger left a comment

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.

tommyettinger
tommyettinger previously approved these changes Apr 13, 2025
Copy link
Member

@tommyettinger tommyettinger left a comment

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
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
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
Member

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

@StartsMercury
Copy link
Author

StartsMercury commented Apr 26, 2025

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

@NathanSweet
Copy link
Member

Sure, it could. The toString mainly for debugging.

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

obigu commented Dec 2, 2025

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

@NathanSweet
Copy link
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.

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

X Tutup