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

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

Closed
lucas-kakele opened this issue Aug 16, 2023 · 4 comments

Comments

@lucas-kakele
Copy link

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!

@tommyettinger
Copy link
Owner

tommyettinger commented Aug 16, 2023

The main issue here is that [] also currently resets styles, such as bold and oblique. Should [] just reset the previous color, or should it reset the previous "thing in square brackets"?

@lucas-kakele
Copy link
Author

Hi Tommy!

I think we can separate the styles applied by square brackets in two categories:

  • toggle styles. eg: bold/italic can only be toggled on and off. there is no stacking
  • stacking styles. eg color and size can be stacked (eg: "[%200]this [%300]is[] a test[]" or "[red]this [green]is[] a test[]")

[] could be used to toggle off styles that are toggled and to reset to the previous state (a stack pop) for stacking styles.

What do you think?

tommyettinger added a commit that referenced this issue Aug 16, 2023
Now the tag `[ ]` is used to do a full reset, and `[]` should only undo the last square-bracket markup change. Things are a little tricky with curly-brace effect markup, and I don't know how this could undo those.
@tommyettinger
Copy link
Owner

Currently what I have implemented just records whenever there's a change to the color/style/size/font-family state, and using [] should (soon?) drop back one step in the history. Getting this to work with TypingLabel effects, which use {EFFECT=parameters;for;it}, is going to be more interesting.

@tommyettinger
Copy link
Owner

This should work for all square-bracket markup now. I don't see a good way to have it affect curly-brace effects, yet. You can try this (and some more related features) in https://github.com/tommyettinger/textratypist/releases/tag/v0.10.0 ; note that [ ] has replaced the old TextraTypist [] and now [] should act how it does for BitmapFont.

hojat72elect pushed a commit to hojat72elect/textratypist that referenced this issue Jun 19, 2024
Now the tag `[ ]` is used to do a full reset, and `[]` should only undo the last square-bracket markup change. Things are a little tricky with curly-brace effect markup, and I don't know how this could undo those.


Former-commit-id: 6d74976
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