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

TextraLabel wrap will not respect prefWidth for long words #11

Open
lucas-kakele opened this issue Aug 14, 2023 · 2 comments
Open

TextraLabel wrap will not respect prefWidth for long words #11

lucas-kakele opened this issue Aug 14, 2023 · 2 comments

Comments

@lucas-kakele
Copy link

Hi!

I'm using the TextraTypist library (which is awesome by the way!) for the labels in my game.

Something I noticed is that labels won't wrap long words properly. It looks like TextraLabel with wrap does not respect the preferred width for long words:

image

Code (using the default skin at https://github.com/czyzby/gdx-skins/tree/master/default/skin):

public class MyGdxGame extends ApplicationAdapter {

  private Stage stage;
  private Skin skin;

  @Override
  public void create () {
    stage = new Stage(new ScreenViewport());

    skin = new Skin(Gdx.files.internal("uiskin.json"));

    TextraLabel label = new TextraLabel("xdddddddddddddddddddddddddddddddddddddddddddddddddddddddd", skin);
    label.setWrap(true);

    Table table = new Table();
    table.debug();
    table.add(label).prefWidth(100).row();

    Stack stack = new Stack(table);
    stack.setFillParent(true);

    stage.addActor(stack);
  }

  @Override
  public void render () {
    ScreenUtils.clear(0, 0, 0, 1);
    stage.act();
    stage.draw();
  }

  @Override
  public void dispose () {
    stage.dispose();
    skin.dispose();
  }
}
@tommyettinger
Copy link
Owner

The behavior here is different from Label, and I've been aware of this for some time. I do want to make the wrapping behavior match Label at some point in the near future, it's just a ton of work.

Right now, the rules wrapping follows are:

  • It never breaks up individual words regardless of length.
    • This is why very long words can be longer than the preferred width.
    • Without hyphenation logic, which is a can of worms, breaking up words can change their meaning.
      • THEPOWEROFCHRIS
      • TCOMPELSYOU!
      • "Huh, why isn't the exorcism working? Are you praying to Chris or something?"
  • If placing the second or later word on a Line would make the Line longer than the Layout's targetWidth, it moves the new word to the next Line.
  • Certain characters count as whitespace, and are replaced with a newline, and certain characters permit being used as a line-break point (such as '-'), and are retained along with a newline after them.

@lucas-kakele
Copy link
Author

Thanks for the elaborated answer Tommy. For the time being, I will use a workaround and manually break long words. Cheers!

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

No branches or pull requests

2 participants