Search code examples
javalibgdxscene2d

Libgdx center Scaled Textbutton in HorizontalGroup


Putting TextBttons into a HorizontalGroup, then scaling them results in a distorted view, even with centered alignment.

add_button = new TextButton("+",textButtonStyle);
add_button.setTransform(true);
add_button.setScale(0.7f);
add_button.setDebug(true);
remove_button = new TextButton("-",textButtonStyle);
remove_button.setTransform(true);
remove_button.setScale(0.7f);
remove_button.setDebug(true);

HorizontalGroup brush_op_group = new HorizontalGroup();
brush_op_group.addActor(remove_button);
brush_op_group.addActor(add_button);
brush_op_group.setDebug(true);

which results in the below image:

enter image description here

It seems like the buttons positions are calculated based on their unscaled sizes. How can this be corrected?


Solution

  • For this purpose I ended up using tables:

    add_button = new TextButton("+",textButtonStyle);
    add_button.setTransform(true);
    add_button.setOrigin(Align.left | Align.top);
    add_button.setScale(0.8f);
    remove_button = new TextButton("-",textButtonStyle);
    remove_button.setTransform(true);
    remove_button.setOrigin(Align.right | Align.top);
    remove_button.setScale(0.8f);
    
    HorizontalGroup file_op_group = new HorizontalGroup();
    Table brush_op_group = new Table().center();
    brush_op_group.add(remove_button).right();
    brush_op_group.add(add_button).left();
    brush_op_group.setDebug(true);
    

    Works like a charm!

    enter image description here