@@ -23,6 +23,7 @@ public class TextWidget<W extends TextWidget<W>> extends Widget<W> {
2323 private IntSupplier color = null ;
2424 private Boolean shadow = null ;
2525 private float scale = 1f ;
26+ private int maxWidth = -1 ;
2627
2728 private String lastText = null ;
2829 private String textForDefaultSize = null ;
@@ -79,6 +80,8 @@ public int getDefaultHeight() {
7980 float maxWidth ;
8081 if (resizer ().isWidthCalculated ()) {
8182 maxWidth = getArea ().width + this .scale ;
83+ } else if (this .maxWidth > 0 ) {
84+ maxWidth = Math .max (this .maxWidth , 5 );
8285 } else if (getParent ().resizer ().isWidthCalculated ()) {
8386 maxWidth = getParent ().getArea ().width + this .scale ;
8487 } else {
@@ -90,9 +93,13 @@ public int getDefaultHeight() {
9093
9194 @ Override
9295 public int getDefaultWidth () {
93- float maxWidth = getScreen ().getScreenArea ().width ;
94- if (getParent ().resizer ().isWidthCalculated ()) {
96+ float maxWidth ;
97+ if (this .maxWidth > 0 ) {
98+ maxWidth = Math .max (this .maxWidth , 5 );
99+ } else if (getParent ().resizer ().isWidthCalculated ()) {
95100 maxWidth = getParent ().getArea ().width ;
101+ } else {
102+ maxWidth = getScreen ().getScreenArea ().width ;
96103 }
97104 TextRenderer renderer = simulate (maxWidth );
98105 return getWidgetWidth (renderer .getLastActualWidth ());
@@ -178,4 +185,9 @@ public W style(TextFormatting formatting) {
178185 this .key .style (formatting );
179186 return getThis ();
180187 }
188+
189+ public W maxWidth (int maxWidth ) {
190+ this .maxWidth = maxWidth ;
191+ return getThis ();
192+ }
181193}
0 commit comments