aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java
index 7392b257a..6edb9b004 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java
@@ -5,6 +5,7 @@
package me.shedaniel.rei.gui.widget;
+import me.shedaniel.math.api.Point;
import me.shedaniel.math.api.Rectangle;
import me.shedaniel.rei.impl.ScreenHelper;
import net.minecraft.client.gui.Element;
@@ -14,19 +15,36 @@ import java.util.List;
public class LabelWidget extends WidgetWithBounds {
- public int x;
- public int y;
- public String text;
+ private Point pos;
+ private String text;
private int defaultColor;
private boolean hasShadows = true;
+ private boolean centered = true;
+ @Deprecated
public LabelWidget(int x, int y, String text) {
- this.x = x;
- this.y = y;
+ this(new Point(x, y), text);
+ }
+
+ public LabelWidget(Point point, String text) {
+ this.pos = point;
this.text = text;
this.defaultColor = ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : -1;
}
+ public boolean isCentered() {
+ return centered;
+ }
+
+ public void setCentered(boolean centered) {
+ this.centered = centered;
+ }
+
+ public LabelWidget centered() {
+ setCentered(true);
+ return this;
+ }
+
public boolean isHasShadows() {
return hasShadows;
}
@@ -35,6 +53,11 @@ public class LabelWidget extends WidgetWithBounds {
this.hasShadows = hasShadows;
}
+ public LabelWidget noShadow() {
+ setHasShadows(false);
+ return this;
+ }
+
public int getDefaultColor() {
return defaultColor;
}
@@ -43,6 +66,24 @@ public class LabelWidget extends WidgetWithBounds {
this.defaultColor = defaultColor;
}
+ public Point getPosition() {
+ return pos;
+ }
+
+ public LabelWidget setPosition(Point position) {
+ this.pos = position;
+ return this;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public LabelWidget setText(String text) {
+ this.text = text;
+ return this;
+ }
+
public LabelWidget color(int defaultColor) {
this.defaultColor = defaultColor;
return this;
@@ -51,7 +92,8 @@ public class LabelWidget extends WidgetWithBounds {
@Override
public Rectangle getBounds() {
int width = font.getStringWidth(text);
- return new Rectangle(x - width / 2 - 1, y - 5, width + 2, 14);
+ Point pos = getPosition();
+ return new Rectangle(pos.x - width / 2 - 1, pos.y - 5, width + 2, 14);
}
@Override
@@ -62,9 +104,10 @@ public class LabelWidget extends WidgetWithBounds {
@Override
public void render(int mouseX, int mouseY, float delta) {
int width = font.getStringWidth(text);
+ Point pos = getPosition();
if (hasShadows)
- font.drawWithShadow(text, x - width / 2, y, defaultColor);
- else font.draw(text, x - width / 2, y, defaultColor);
+ font.drawWithShadow(text, pos.x - width / 2, pos.y, defaultColor);
+ else font.draw(text, pos.x - width / 2, pos.y, defaultColor);
}
}