Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public WWindow window(WWidget icon, String title) {

@Override
public WLabel label(String text, boolean title, double maxWidth) {
if (maxWidth == 0) return w(new WMeteorLabel(text, title));
if (maxWidth == 0 && !text.contains("\n")) return w(new WMeteorLabel(text, title));
return w(new WMeteorMultiLabel(text, title, maxWidth));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package meteordevelopment.meteorclient.gui.widgets;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class WMultiLabel extends WLabel {
Expand All @@ -25,51 +24,59 @@ protected void onCalculateSize() {
lines.clear();

String[] textLines = text.split("\n");
StringBuilder sb = new StringBuilder();
double maxLineWidth = 0;

double spaceWidth = theme.textWidth(" ", 1, title);
double maxWidth = theme.scale(this.maxWidth);
if (this.maxWidth == 0) {
for (String line : textLines) {
lines.add(line);
double lineWidth = theme.textWidth(line, line.length(), title);
maxLineWidth = Math.max(maxLineWidth, lineWidth);
}
} else {
StringBuilder sb = new StringBuilder();

double lineWidth = 0;
double maxLineWidth = 0;
double lineWidth = 0;
double spaceWidth = theme.textWidth(" ", 1, title);
double maxWidth = theme.scale(this.maxWidth);

int iInLine = 0;
int iInLine = 0;

for (String line : textLines) {
for (String word : line.split(" ")) {
double wordWidth = theme.textWidth(word, word.length(), title);
for (String line : textLines) {
for (String word : line.split(" ")) {
double wordWidth = theme.textWidth(word, word.length(), title);

double toAdd = wordWidth;
if (iInLine > 0) toAdd += spaceWidth;
double toAdd = wordWidth;
if (iInLine > 0) toAdd += spaceWidth;

if (lineWidth + toAdd > maxWidth) {
lines.add(sb.toString());
sb.setLength(0);
if (lineWidth + toAdd > maxWidth) {
lines.add(sb.toString());
sb.setLength(0);

sb.append(word);
lineWidth = wordWidth;
iInLine = 1;
sb.append(word);
lineWidth = wordWidth;
iInLine = 1;

} else {
if (iInLine > 0) {
sb.append(' ');
lineWidth += spaceWidth;
}
} else {
if (iInLine > 0) {
sb.append(' ');
lineWidth += spaceWidth;
}

sb.append(word);
lineWidth += wordWidth;
iInLine++;
sb.append(word);
lineWidth += wordWidth;
iInLine++;
}
// now this line is not pointless!
maxLineWidth = Math.max(maxLineWidth, lineWidth);
}
// now this line is not pointless!
maxLineWidth = Math.max(maxLineWidth, lineWidth);
lines.add(sb.toString());
sb.setLength(0);
lineWidth = 0;
iInLine = 0;
}
lines.add(sb.toString());
sb.setLength(0);
lineWidth = 0;
iInLine = 0;
}

if (!sb.isEmpty()) lines.add(sb.toString());
if (!sb.isEmpty()) lines.add(sb.toString());
}

width = maxLineWidth;
height = theme.textHeight(title) * lines.size();
Expand Down