tommyettinger / textratypist

Augmented text display system for libGDX, based on typing-label
Apache License 2.0
94 stars 9 forks source link

TextraLabel wrap will not respect prefWidth for long words #11

Open lucas-kakele opened 1 year ago

lucas-kakele commented 1 year ago

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 commented 1 year ago

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:

lucas-kakele commented 1 year ago

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