Libgdx在HorizontalGroup中居中缩放的TextButton

huangapple go评论82阅读模式
英文:

Libgdx center Scaled Textbutton in HorizontalGroup

问题

将TextButtons放入HorizontalGroup中,然后对它们进行缩放会导致视图失真,即使采用了居中对齐。

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);

这将导致如下图像:

Libgdx在HorizontalGroup中居中缩放的TextButton

似乎按钮的位置是基于它们未缩放大小计算的。
如何纠正这个问题?

英文:

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:

Libgdx在HorizontalGroup中居中缩放的TextButton

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

答案1

得分: 0

以下是翻译好的部分:

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);

运作得很好!

Libgdx在HorizontalGroup中居中缩放的TextButton

英文:

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!

Libgdx在HorizontalGroup中居中缩放的TextButton

huangapple
  • 本文由 发表于 2020年5月29日 19:22:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/62084796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定