Skip to content

Commit e4d2d81

Browse files
committed
reset formatting state on each text element
1 parent 1db1b02 commit e4d2d81

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/com/cleanroommc/modularui/drawable/text/RichTextCompiler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void reset(FontRenderer fr, int maxWidth) {
5454

5555
private void compile(List<Object> raw) {
5656
for (Object o : raw) {
57+
this.formatting.reset();
5758
if (o instanceof ITextLine line) {
5859
newLine();
5960
lines.add(line);
@@ -157,7 +158,11 @@ private void compileString(String text) {
157158
private void newLine() {
158159
int i = currentLine.size() - 1;
159160
if (!currentLine.isEmpty() && currentLine.get(i) instanceof String s) {
160-
if (s.equals(" ")) {currentLine.remove(i);} else currentLine.set(i, trimRight(s));
161+
if (s.equals(" ")) {
162+
currentLine.remove(i);
163+
} else {
164+
currentLine.set(i, trimRight(s));
165+
}
161166
}
162167
if (currentLine.isEmpty()) {
163168
//lines.add(null);

src/main/java/com/cleanroommc/modularui/test/TestGuis.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import net.minecraft.item.ItemStack;
2323
import net.minecraft.util.EnumFacing;
2424

25+
import net.minecraft.util.text.TextFormatting;
26+
2527
import org.jetbrains.annotations.NotNull;
2628

2729
import java.util.ArrayList;
@@ -68,7 +70,8 @@ public class TestGuis extends CustomModularScreen {
6870
.add(new ItemDrawable(new ItemStack(Blocks.GRASS))
6971
.asIcon()
7072
.asHoverable()
71-
.tooltip(richTooltip -> richTooltip.addFromItem(new ItemStack(Blocks.GRASS))))
73+
.tooltip(richTooltip -> richTooltip.addFromItem(new ItemStack(Blocks.GRASS))
74+
.add(TextFormatting.GRAY + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.")))
7275
.add(", nice to ")
7376
.add(new ItemDrawable(new ItemStack(Items.PORKCHOP))
7477
.asIcon()
@@ -101,6 +104,10 @@ public class TestGuis extends CustomModularScreen {
101104
IKey.str("red").style(IKey.RED),
102105
IKey.str("underline").style(null, IKey.UNDERLINE)
103106
).style(IKey.GREEN))
107+
.newLine()
108+
.add(TextFormatting.RESET + "" + TextFormatting.UNDERLINE + "Underlined" + TextFormatting.RESET)
109+
.newLine()
110+
.add("A long line which should wrap around")
104111
.textShadow(false)
105112
));
106113
}

0 commit comments

Comments
 (0)