Skip to content

Commit 11e7219

Browse files
authored
Add methods for centered string rendering with TesseractGuiGraphics (#110)
1 parent 483ba41 commit 11e7219

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

src/main/java/net/swedz/tesseract/neoforge/helper/guigraphics/StringGuiGraphics.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,47 @@ default int drawString(FormattedCharSequence text, int x, int y)
2424
return this.drawString(text, (float) x, (float) y);
2525
}
2626

27-
int drawString(String text, float x, float y);
27+
default int drawCenteredString(String text, int x, int y)
28+
{
29+
return this.drawCenteredString(text, (float) x, (float) y);
30+
}
31+
32+
default int drawCenteredString(Component text, int x, int y)
33+
{
34+
return this.drawCenteredString(text, (float) x, (float) y);
35+
}
36+
37+
default int drawCenteredString(FormattedCharSequence text, int x, int y)
38+
{
39+
return this.drawCenteredString(text, (float) x, (float) y);
40+
}
41+
42+
default int drawString(String text, float x, float y)
43+
{
44+
return this.drawString(Component.literal(text), x, y);
45+
}
46+
47+
default int drawString(Component text, float x, float y)
48+
{
49+
return this.drawString(text.getVisualOrderText(), x, y);
50+
}
2851

2952
int drawString(FormattedCharSequence text, float x, float y);
53+
54+
default int drawCenteredString(String text, float x, float y)
55+
{
56+
return this.drawCenteredString(Component.literal(text), x, y);
57+
}
58+
59+
default int drawCenteredString(Component text, float x, float y)
60+
{
61+
return this.drawCenteredString(text.getVisualOrderText(), x, y);
62+
}
63+
64+
default int drawCenteredString(FormattedCharSequence text, float x, float y)
65+
{
66+
x -= this.getFont().width(text) / 2f;
67+
y -= this.getFont().lineHeight / 2f;
68+
return this.drawString(text, (float) Math.round(x), (float) Math.round(y));
69+
}
3070
}

src/main/java/net/swedz/tesseract/neoforge/helper/guigraphics/TesseractGuiGraphics.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,6 @@ public void fill(RenderType renderType, int minX, int minY, int maxX, int maxY,
347347
this.delayed(() -> internal.fill(renderType, minX, minY, maxX, maxY, z, color));
348348
}
349349

350-
@Override
351-
public int drawString(String text, float x, float y)
352-
{
353-
return internal.drawString(font, text, x, y, this.getColorARGB(), this.isStringDropShadow());
354-
}
355-
356350
@Override
357351
public int drawString(FormattedCharSequence text, float x, float y)
358352
{

0 commit comments

Comments
 (0)