Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LIBGDX : add a clickable text link

I'm developing a little game with libgdx and in my about screen I would like to have a label (wrapped in a table) in which there would have a clickable text link (underlined or with a different color) like this:

You can review the code here

here

Edit:

What I've tried is:

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 me this

this

like image 214
Bat Red Avatar asked Dec 04 '14 12:12

Bat Red


1 Answers

If you need only a portion of the Label clickable, I think the best way to implement this is having two Labels, 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);
like image 99
Juan Javier Cassani Avatar answered Nov 14 '22 02:11

Juan Javier Cassani