Skip to content

Commit 9ca3142

Browse files
committed
merge any strings in a composed line
1 parent 063b525 commit 9ca3142

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/main/java/com/cleanroommc/modularui/api/drawable/IHoverable.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
import org.jetbrains.annotations.ApiStatus;
88
import org.jetbrains.annotations.Nullable;
99

10+
/**
11+
* This marks an {@link IDrawable} as hoverable in a {@link com.cleanroommc.modularui.drawable.text.RichText RichText}. This should not be
12+
* extended in most cases instead obtain an instance by calling {@link IIcon#asHoverable()}.
13+
*/
14+
@ApiStatus.NonExtendable
1015
public interface IHoverable extends IIcon {
1116

1217
/**
13-
* Called every frame this hoverable is hovered inside a {@link com.cleanroommc.modularui.drawable.text.RichText}.
18+
* Called every frame this hoverable is hovered inside a {@link com.cleanroommc.modularui.drawable.text.RichText RichText}.
1419
*/
1520
default void onHover() {}
1621

@@ -19,7 +24,13 @@ default RichTooltip getTooltip() {
1924
return null;
2025
}
2126

27+
/**
28+
* An internal function to set the current rendered position. This is used to detect if this element is under the mouse.
29+
*/
2230
void setRenderedAt(int x, int y);
2331

32+
/**
33+
* @return the last area this drawable was drawn at.
34+
*/
2435
Area getRenderedArea();
2536
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ private void newLine() {
182182

183183
private void addLineElement(Object o) {
184184
if (o instanceof String s2) {
185-
if (this.currentLine.size() == 1 && this.currentLine.get(0) instanceof String s1) {
186-
// if there is already one string in the line, merge them
187-
this.currentLine.set(0, s1 + s2);
185+
int s = this.currentLine.size();
186+
if (s > 0 && this.currentLine.get(s - 1) instanceof String s1) {
187+
// if the last element in the line is a string, merge them
188+
this.currentLine.set(s - 1, s1 + s2);
188189
return;
189190
}
190191
if (this.currentLine.isEmpty()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class TestGuis extends CustomModularScreen {
4949

5050
@Override
5151
public @NotNull ModularPanel buildUI(ModularGuiContext context) {
52-
return buildListUi(context);
52+
return buildRichTextUI(context);
5353
}
5454

5555
public @NotNull ModularPanel buildAnimationUI(ModularGuiContext context) {

0 commit comments

Comments
 (0)