Aeonia Aeonia - 3 months ago 24
iOS Question

Libgdx TextField won't resize

I have a textfield that simply won't scale, expand ,fill,setWidth nothing works. I have already placed it in a table cell but that didnt help...

This what I have:

enter image description here

I want the text to scale and fit all the red region...

field = new TextField("", skin4);
// field.setCursorPosition(0);
field.setMaxLength(6);
field.setMessageText("0.00");
field.setWidth(2f);
field.setHeight(1f);
field.setScale(2, 2);
//group.addActor(field);

Table table = new Table();
table.setPosition(100, 180);
table.setSize(150, 90);
table.add(field).height(80).fill().expand();
table.setDebug(true);
table.row();

group.addActor(table);
stage.addActor(group);


Skin

skin4 = new Skin();
font = new BitmapFont(Gdx.files.internal("future.fnt"), true);
buttonAtlas = new TextureAtlas(Gdx.files.internal("cursor/cursor.pack"));
skin4.addRegions(buttonAtlas);
textFieldStyle = new TextField.TextFieldStyle();
textFieldStyle.font = font;
textFieldStyle.cursor = skin4.getDrawable("cursor_text");
textFieldStyle.cursor.setMinWidth(10f);
skin4.add("default", textFieldStyle);

Answer

All I had to do was change my font to a FreeTypeFont generator that can easily scale the font given distorting quality..Like below..

        skin4 = new Skin();
        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("future.ttf"));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        //change font size here
        parameter.size = 40;
        parameter.flip = true;
        BitmapFont font25 = generator.generateFont(parameter);

        labelStyle = new Label.LabelStyle();
        labelStyle.font = font25;
        skin4.add("default", labelStyle);
Comments