aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFalkreon <falkreon@gmail.com>2019-08-31 15:15:22 -0500
committerFalkreon <falkreon@gmail.com>2019-08-31 15:15:22 -0500
commitf0fba38f40ad2beda06a638356d4ef47e62cd03b (patch)
tree828150caf2f85a1381d6a631a4ce86d0dce6fbed /src
parent126fbe5c3e5b4b4eb9c459e9b1047bad5be34ca4 (diff)
downloadLibGui-f0fba38f40ad2beda06a638356d4ef47e62cd03b.tar.gz
LibGui-f0fba38f40ad2beda06a638356d4ef47e62cd03b.tar.bz2
LibGui-f0fba38f40ad2beda06a638356d4ef47e62cd03b.zip
Fix Alignment, add to WLabel and WButton
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java12
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java15
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java2
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