@@ -22,6 +22,7 @@ public class TextWidget extends Widget<TextWidget> {
2222 private float scale = 1f ;
2323
2424 private String lastText = null ;
25+ private String textForDefaultSize = null ;
2526
2627 public TextWidget (IKey key ) {
2728 this .key = key ;
@@ -52,7 +53,7 @@ private TextRenderer simulate(float maxWidth) {
5253 renderer .setPos (padding .left , padding .top );
5354 renderer .setScale (this .scale );
5455 renderer .setSimulate (true );
55- renderer .draw (this . key . getFormatted ());
56+ renderer .draw (getTextForDefaultSize ());
5657 renderer .setSimulate (false );
5758 return renderer ;
5859 }
@@ -91,6 +92,23 @@ protected int getWidgetHeight(float actualTextHeight) {
9192 return Math .max (1 , (int ) Math .ceil (actualTextHeight + padding .vertical ()));
9293 }
9394
95+ /**
96+ * Makes sure the used text for {@link #getDefaultWidth()} and {@link #getDefaultHeight()} is always the same.
97+ * Also sets the last rendered text.
98+ */
99+ protected String getTextForDefaultSize () {
100+ if (this .textForDefaultSize == null ) {
101+ this .textForDefaultSize = this .key .getFormatted ();
102+ this .lastText = this .textForDefaultSize ;
103+ }
104+ return this .textForDefaultSize ;
105+ }
106+
107+ @ Override
108+ public void postResize () {
109+ this .textForDefaultSize = null ;
110+ }
111+
94112 public IKey getKey () {
95113 return this .key ;
96114 }
0 commit comments