66package meteordevelopment .meteorclient .gui .widgets ;
77
88import java .util .ArrayList ;
9- import java .util .Arrays ;
109import java .util .List ;
1110
1211public abstract class WMultiLabel extends WLabel {
@@ -25,51 +24,59 @@ protected void onCalculateSize() {
2524 lines .clear ();
2625
2726 String [] textLines = text .split ("\n " );
28- StringBuilder sb = new StringBuilder () ;
27+ double maxLineWidth = 0 ;
2928
30- double spaceWidth = theme .textWidth (" " , 1 , title );
31- double maxWidth = theme .scale (this .maxWidth );
29+ if (this .maxWidth == 0 ) {
30+ for (String line : textLines ) {
31+ lines .add (line );
32+ double lineWidth = theme .textWidth (line , line .length (), title );
33+ maxLineWidth = Math .max (maxLineWidth , lineWidth );
34+ }
35+ } else {
36+ StringBuilder sb = new StringBuilder ();
3237
33- double lineWidth = 0 ;
34- double maxLineWidth = 0 ;
38+ double lineWidth = 0 ;
39+ double spaceWidth = theme .textWidth (" " , 1 , title );
40+ double maxWidth = theme .scale (this .maxWidth );
3541
36- int iInLine = 0 ;
42+ int iInLine = 0 ;
3743
38- for (String line : textLines ) {
39- for (String word : line .split (" " )) {
40- double wordWidth = theme .textWidth (word , word .length (), title );
44+ for (String line : textLines ) {
45+ for (String word : line .split (" " )) {
46+ double wordWidth = theme .textWidth (word , word .length (), title );
4147
42- double toAdd = wordWidth ;
43- if (iInLine > 0 ) toAdd += spaceWidth ;
48+ double toAdd = wordWidth ;
49+ if (iInLine > 0 ) toAdd += spaceWidth ;
4450
45- if (lineWidth + toAdd > maxWidth ) {
46- lines .add (sb .toString ());
47- sb .setLength (0 );
51+ if (lineWidth + toAdd > maxWidth ) {
52+ lines .add (sb .toString ());
53+ sb .setLength (0 );
4854
49- sb .append (word );
50- lineWidth = wordWidth ;
51- iInLine = 1 ;
55+ sb .append (word );
56+ lineWidth = wordWidth ;
57+ iInLine = 1 ;
5258
53- } else {
54- if (iInLine > 0 ) {
55- sb .append (' ' );
56- lineWidth += spaceWidth ;
57- }
59+ } else {
60+ if (iInLine > 0 ) {
61+ sb .append (' ' );
62+ lineWidth += spaceWidth ;
63+ }
5864
59- sb .append (word );
60- lineWidth += wordWidth ;
61- iInLine ++;
65+ sb .append (word );
66+ lineWidth += wordWidth ;
67+ iInLine ++;
68+ }
69+ // now this line is not pointless!
70+ maxLineWidth = Math .max (maxLineWidth , lineWidth );
6271 }
63- // now this line is not pointless!
64- maxLineWidth = Math .max (maxLineWidth , lineWidth );
72+ lines .add (sb .toString ());
73+ sb .setLength (0 );
74+ lineWidth = 0 ;
75+ iInLine = 0 ;
6576 }
66- lines .add (sb .toString ());
67- sb .setLength (0 );
68- lineWidth = 0 ;
69- iInLine = 0 ;
70- }
7177
72- if (!sb .isEmpty ()) lines .add (sb .toString ());
78+ if (!sb .isEmpty ()) lines .add (sb .toString ());
79+ }
7380
7481 width = maxLineWidth ;
7582 height = theme .textHeight (title ) * lines .size ();
0 commit comments