LIBGDX: add clickable text link

I am developing a small game with libgdx and in my screen I would like to have a shortcut (wrapped in a table) where a link with text (underlined or with a different color) would be available:

You can view the code here

here

Edit:

I tried:

HorizontalGroup monGroup = new HorizontalGroup();
Label howRotationRep = new Label("They have been based on the information provided on this ", new Label.LabelStyle(game.petiteFont, Color.WHITE));
howRotationRep.setWrap(true);
howRotationRep.setWidth(tailleCell);

Label test = new Label(" site", new Label.LabelStyle(game.petiteFont, Color.RED));
test.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {

   Gdx.net.openURI("http://tetrisconcept.net/wiki/SRS");

}
});
monGroup.addActor(howRotationRep);
monGroup.addActor(test);
table.add(monGroup).left().width(tailleCell);

      

And it gives it to me

this

+3


source to share


2 answers


If you only want the Clickable part of the shortcut, I think the best way to implement it is to have two shortcuts, this should work:



    Label lblReviewCode = new Label("You can review the code ", skin);
    Label lblReviewCodeLink = new Label("here", skin, "linkstyle");
    // If you don't want to provide a custom style...
    //Label lblReviewCodeLink = new Label("here", skin);
    lblReviewCodeLink.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Gdx.net.openURI("https://bitbucket.org/batman3000/batris");
        }
    });
    // If you didn't provided the style, you can at least paint it blue by doing this...
    //lblReviewCodeLink.setColor(Color.BLUE);

    HorizontalGroup codeLink = new HorizontalGroup();
    codeLink.addActor(lblReviewCode);
    codeLink.addActor(lblReviewCodeLink);

    table.add(codeLink);

      

+5


source


You can do this by using two different scene2d labels like "you can view the code" and "here" and set a second click listener. You can simply change the color of the "here" label and place it according to the position of the first labels, for example using the following pseduo code:



label2.x = label1.x + label1.getTextWidth();
label2.y = label1.y;

      

0


source







All Articles