libgdx icon indicating copy to clipboard operation
libgdx copied to clipboard

GlyphLayout: justify text option(s)

Open StartsMercury opened this issue 10 months ago • 7 comments

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.

StartsMercury avatar Mar 16 '25 07:03 StartsMercury

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.

NathanSweet avatar Apr 22 '25 23:04 NathanSweet

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?

StartsMercury avatar Apr 23 '25 06:04 StartsMercury

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

NathanSweet avatar Apr 25 '25 16:04 NathanSweet

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

StartsMercury avatar Apr 26 '25 06:04 StartsMercury

Sure, it could. The toString mainly for debugging.

NathanSweet avatar Apr 27 '25 19:04 NathanSweet