Search code examples
javabuttonfontslibgdxtruetype

LibGDX True Type Font usage in button


so I'm trying to use true type button, I managed to do that wih label and it worked well, but now I don't know how to use it with Buttons. I'am using GDX freetype library.

I used in label:

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("LoginScreen/Fonts/bebas.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = (int) (0.05f * (stage.getHeight()));
    BitmapFont font12 = generator.generateFont(parameter); // font size 12 pixels
    generator.dispose(); // don't forget to dispose to avoid memory leaks!

    LabelStyle labelStyle = new LabelStyle(font12, new Color(0, 0, 0, 0.5f));
    windowTitle = new Label("Login or register", labelStyle);

I need in button:

loginButton = new TextButton("Sign in", skin, "default");
loginButton.getLabel().setFontScale(0.00444f * table.getWidth());

Solution

  • There's a class to add style to your button:

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = font12;
    loginButton = new TextButton("Sign in", textButtonStyle);
    

    But you have to configure another things too.