Skip to content

Commit 1884b53

Browse files
committed
fix: Config field titles are now left aligned, rather than center aligned
closes #17
1 parent c764c78 commit 1884b53

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix crash on dedicated servers.
1+
- (fix) Config field titles are now left aligned, rather than center aligned (#17)

common/src/client/java/io/github/jamalam360/jamlib/client/gui/ScrollingStringWidget.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package io.github.jamalam360.jamlib.client.gui;
22

3+
import net.minecraft.Util;
34
import net.minecraft.client.Minecraft;
45
import net.minecraft.client.gui.Font;
56
import net.minecraft.client.gui.GuiGraphics;
67
import net.minecraft.client.gui.components.StringWidget;
78
import net.minecraft.network.chat.Component;
9+
import net.minecraft.util.Mth;
810

911
/**
1012
* A string widget that scrolls if the component is too long for the width
@@ -16,10 +18,28 @@ public ScrollingStringWidget(int x, int y, int width, int height, Component comp
1618

1719
@Override
1820
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
19-
this.renderScrollingString(guiGraphics, this.getFont(), 2, this.getColor());
21+
renderLeftAlignedScrollingString(guiGraphics, this.getFont(), this.getMessage(), this.getX(), this.getWidth(), this.getY(), this.getColor());
2022

2123
if (this.isMouseOver(mouseX, mouseY) && this.getTooltip() != null) {
2224
guiGraphics.renderTooltip(Minecraft.getInstance().font, this.getTooltip().toCharSequence(Minecraft.getInstance()), mouseX, mouseY);
2325
}
2426
}
27+
28+
private static void renderLeftAlignedScrollingString(GuiGraphics graphics, Font font, Component text, int minX, int width, int y, int color) {
29+
int messageWidth = font.width(text);
30+
31+
if (messageWidth > width) {
32+
int overflowWidth = messageWidth - width;
33+
double d = (double) Util.getMillis() / (double)1000.0F;
34+
double e = Math.max((double)overflowWidth * (double)0.5F, 3.0F);
35+
double f = Math.sin((Math.PI / 2D) * Math.cos((Math.PI * 2D) * d / e)) / (double)2.0F + (double)0.5F;
36+
double g = Mth.lerp(f, 0.0F, overflowWidth);
37+
graphics.enableScissor(minX, y, minX + width, y + font.lineHeight);
38+
graphics.drawString(font, text, minX - (int)g, y, color);
39+
graphics.disableScissor();
40+
} else {
41+
graphics.drawString(font, text, minX, y, color);
42+
}
43+
44+
}
2545
}

0 commit comments

Comments
 (0)