diff options
3 files changed, 19 insertions, 10 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index 243c885..31ab670 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java @@ -224,14 +224,14 @@ public class ScreenDrawing { break; case CENTER: { int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s); - int l = (width-2) - (wid/2); - MinecraftClient.getInstance().textRenderer.draw(s, l, y, color); + int l = (width/2) - (wid/2); + MinecraftClient.getInstance().textRenderer.draw(s, x+l, y, color); } break; case RIGHT: { int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s); int l = width - wid; - MinecraftClient.getInstance().textRenderer.draw(s, l, y, color); + MinecraftClient.getInstance().textRenderer.draw(s, x+l, y, color); } break; } @@ -245,14 +245,14 @@ public class ScreenDrawing { break; case CENTER: { int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s); - int l = (width-2) - (wid/2); - MinecraftClient.getInstance().textRenderer.drawWithShadow(s, l, y, color); + int l = (width/2) - (wid/2); + MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x+l, y, color); } break; case RIGHT: { int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s); int l = width - wid; - MinecraftClient.getInstance().textRenderer.drawWithShadow(s, l, y, color); + MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x+l, y, color); } break; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java index f491238..1064117 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java @@ -1,6 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.widget.data.Alignment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.sound.PositionedSoundInstance; @@ -12,6 +13,7 @@ public class WButton extends WWidget { protected int color = WLabel.DEFAULT_TEXT_COLOR; protected int darkmodeColor = WLabel.DEFAULT_TEXT_COLOR; private boolean enabled = true; + protected Alignment alignment = Alignment.CENTER; private Runnable onClick; @@ -57,7 +59,7 @@ public class WButton extends WWidget { color = 0xFFFFA0; } - ScreenDrawing.drawCenteredWithShadow(label.asFormattedString(), x+(getWidth()/2), y + ((20 - 8) / 2), color); //LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawStringWithShadow(label.asFormattedString(), alignment, x, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color); } } @@ -77,15 +79,22 @@ public class WButton extends WWidget { } } - public void setOnClick(Runnable r) { + public WButton setOnClick(Runnable r) { this.onClick = r; + return this; } public boolean isEnabled() { return enabled; } - public void setEnabled(boolean enabled) { + public WButton setEnabled(boolean enabled) { this.enabled = enabled; + return this; + } + + public WButton setAlignment(Alignment alignment) { + this.alignment = alignment; + return this; } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java index 0966a20..94fc8ff 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java @@ -31,7 +31,7 @@ public class WLabel extends WWidget { @Override public void paintBackground(int x, int y) { String translated = text.asFormattedString(); - ScreenDrawing.drawString(translated, x, y, LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawString(translated, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); } @Override |