Giter Site home page Giter Site logo

tommyettinger / textratypist Goto Github PK

View Code? Open in Web Editor NEW
91.0 7.0 10.0 283.33 MB

Augmented text display system for libGDX, based on typing-label

License: Apache License 2.0

Java 99.36% Clojure 0.07% HTML 0.29% CSS 0.28%
font text label libgdx java scene2d gui

textratypist's Introduction

Welcome to my commit streak.

Tommy Ettinger's GitHub stats

Github Contributions

textratypist's People

Contributors

dbder avatar raeleus avatar tommyettinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

textratypist's Issues

Label & TextraLabel feature parity request: [] sets the color to the previous color

Hi!

A current behavior of TextraLabel that does not match Label is the use of [].

That syntax in Label will sets the color to the previous color defined in the label. That syntax in TextraLabel will reset the color to the label original color instead.

Example:

image

Code:

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"));

    Label label = new Label("[RED]test [GREEN]test[] test[]", skin);
    label.getStyle().font.getData().markupEnabled = true;

    TextraLabel textraLabel = new TextraLabel("[red]test [green]test[] test[]", skin);

    Table table = new Table();
    table.add(label).row();
    table.add(textraLabel).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();
  }
}

The request of this issue is to make TextraLabel's [] tag match the behavior of Label.

Thanks!

TextraLabel wrap will not respect prefWidth for long words

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();
  }
}

Spaces cause wrapping to create an extra line for each space

Hi!

When rendering a wrapped TextraLabel that has a lot of spaces, each space will result in an extra line.

Example:

image

Code:

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"));

    int fitOneLineCount = 25;
    int extraLines = 10;

    StringBuilder text = new StringBuilder();
    for (int count = 0; count < fitOneLineCount + extraLines; count++) {
      text.append(' ');
    }

    TextraLabel textraLabel = new TextraLabel(text.toString(), skin);
    textraLabel.setWrap(true);

    // Runs in the next render thread so the layout is ready.
    Gdx.app.postRunnable(() -> System.out.println("Lines: " + textraLabel.layout.lines()));

    Table table = new Table();
    table.debug();
    table.add(textraLabel).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();
  }
}

In the code above, there will be a whole line with spaces only. When it reaches the size of the table row preferred width, each extra space (defined by extraLines in the code) will create a new line.

Let me know if you need more information!

Regards.

Why set glyph just to char

In font, it can be int when add to mapping, but finally only consider it as char with 0xFFFF.
Therefore, if I want to add some image I like, I have to set value lower than 0xFFFF, which is limited.
Why not let glyph value could be long when searching in mapping.

Twemoji glyphs are misaligned

Hi, and thanks for the amazing features this library provides! It's mind-blowing to realize what you can do with those old boring libGDX texts now 🙌

I ran into layout problems using Twemoji. I noticed that the emoji glyphs were misaligned when I tried them with my 9-pixels-high font. I thought, there might be something wrong with my font glyph markup, but emojis behave weird even with the default libGDX font.

val font = Font()
KnownFonts.addEmoji(font)
val label = TypingLabel("[+🤡] This is a [+😄]test message.", font)
label.setPosition(100f, 100f)
label.pack()
label.debug()
stage.addActor(label)

image
image

So clearly, there's space reserved in the text for the emoji glyphs, but they are shifted by a constant value.
Am I missing something? Or maybe there are specific requirements for the font to be compatible with Twemoji?

textratypist version is 0.10.0

Installation/Setup

Hello, sorry but i don't understand well how to include textra typist in my project, could someone be so kind as to explain it in details? Thank you in advance.

Fonts with scale are drawn incorrectly

Hello!

The following code (with the extra invalidateHierarchy call at TextraLabel.layout, from #13 (comment)):

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.github.tommyettinger.textra.TextraLabel;

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"));

    skin.getFont("default-font").getData().setScale(2);

    TextraLabel label = new TextraLabel("This is a test. This is a test. This is a test. This is a test. This is a test.", skin) {
      @Override
      public void layout() {
        float width = getWidth();
        if (style != null && style.background != null) {
          width = (width - (style.background.getLeftWidth() + style.background.getRightWidth()));
        }
        if (wrap && layout.getTargetWidth() != width) {
          if(width != 0)
            layout.setTargetWidth(width);
          font.regenerateLayout(layout);
          invalidateHierarchy(); // Uncomment this line to fix the issue.
        }
      }
    };
    label.setWrap(true);
    label.setAlignment(Align.left);

    Table table = new Table(skin);
    table.setBackground("default-pane");
    table.add(label).prefWidth(300).row();

    Table wrappingTable = new Table();
    wrappingTable.add(table).row();
    wrappingTable.add().growY();

    Stack stack = new Stack(wrappingTable);
    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();
  }
}

Will result in:

image

Without setting the font scale, the label is drawn correctly:

image

The example above is using libGDX 1.12.2-SNAPSHOT and textralabel 6406d6f snapshot.

This also happens to other fonts and also when setting a scale < 1. For example, without scaling:

image

With scale of 0.5f:

image

Let me know if you want me to share the second example resources or if you need more details.

Regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.