Skip to content

Commit 68ec753

Browse files
committed
fix rich tooltip scale & alignment
1 parent b23d762 commit 68ec753

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ default T add(IDrawable drawable) {
1919
return getThis();
2020
}
2121

22+
default T addLine(String s) {
23+
getRichText().add(s).newLine();
24+
return getThis();
25+
}
26+
2227
default T addLine(ITextLine line) {
2328
getRichText().addLine(line);
2429
return getThis();

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ public void drawCompiled(GuiContext context, List<ITextLine> lines) {
127127
}
128128
if (!this.simulate) {
129129
GlStateManager.pushMatrix();
130+
GlStateManager.translate(this.x, this.y, 10);
130131
GlStateManager.scale(this.scale, this.scale, 1f);
132+
GlStateManager.translate(-this.x, -this.y, 0);
131133
}
132-
int y0 = getStartY(height * this.scale);
134+
int y0 = getStartY(height, height);
133135
this.lastY = y0;
134136
for (ITextLine line : lines) {
135-
int x0 = getStartX(line.getWidth() * this.scale);
137+
int x0 = getStartX(width, line.getWidth());
136138
if (!simulate) line.draw(context, getFontRenderer(), x0, y0, this.color, this.shadow);
137139
y0 += line.getHeight(getFontRenderer());
138140
}
@@ -209,15 +211,23 @@ protected int getStartYOfLines(int lines) {
209211
}
210212

211213
protected int getStartY(float height) {
212-
if (this.alignment.y > 0 && this.maxHeight > 0) {
213-
return (int) (this.y + (this.maxHeight * this.alignment.y) - height * this.alignment.y);
214+
return getStartY(this.maxHeight, height);
215+
}
216+
217+
protected int getStartY(float maxHeight, float height) {
218+
if (this.alignment.y > 0 && maxHeight > 0 && height != maxHeight) {
219+
return (int) (this.y + (maxHeight * this.alignment.y) - height * this.alignment.y);
214220
}
215221
return this.y;
216222
}
217223

218224
protected int getStartX(float lineWidth) {
219-
if (this.alignment.x > 0 && this.maxWidth > 0) {
220-
return (int) (this.x + (this.maxWidth * this.alignment.x) - lineWidth * this.alignment.x);
225+
return getStartX(this.maxWidth, lineWidth);
226+
}
227+
228+
protected int getStartX(float maxWidth, float lineWidth) {
229+
if (this.alignment.x > 0 && maxWidth > 0) {
230+
return (int) (this.x + (maxWidth * this.alignment.x) - lineWidth * this.alignment.x);
221231
}
222232
return this.x;
223233
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import com.cleanroommc.modularui.drawable.SpriteDrawable;
77
import com.cleanroommc.modularui.screen.CustomModularScreen;
88
import com.cleanroommc.modularui.screen.ModularPanel;
9+
import com.cleanroommc.modularui.screen.RichTooltip;
910
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
11+
import com.cleanroommc.modularui.utils.Alignment;
1012
import com.cleanroommc.modularui.utils.GameObjectHelper;
1113
import com.cleanroommc.modularui.utils.SpriteHelper;
1214
import com.cleanroommc.modularui.utils.fakeworld.ArraySchema;
@@ -33,7 +35,7 @@ public class TestGuis extends CustomModularScreen {
3335

3436
@Override
3537
public @NotNull ModularPanel buildUI(ModularGuiContext context) {
36-
return buildRichTextUI(context);
38+
return buildSpriteUI(context);
3739
}
3840

3941
public @NotNull ModularPanel buildSpriteUI(ModularGuiContext context) {
@@ -44,7 +46,15 @@ public class TestGuis extends CustomModularScreen {
4446
.child(new DraggableWidget<>()
4547
.background(new SpriteDrawable(sprite))
4648
.size(20)
47-
.center());
49+
.center()
50+
.tooltipBuilder(tooltip -> {
51+
tooltip.addLine("Line 1");
52+
tooltip.addLine("Longer Line 2");
53+
tooltip.addLine("Line 3");
54+
tooltip.alignment(Alignment.Center);
55+
tooltip.scale(0.5f);
56+
tooltip.pos(RichTooltip.Pos.NEXT_TO_MOUSE);
57+
}));
4858
}
4959

5060

0 commit comments

Comments
 (0)