diff options
| author | shedaniel <daniel@shedaniel.me> | 2019-11-22 17:23:51 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2019-11-22 17:23:51 +0800 |
| commit | 0710ab56e7e8f76670dab785b907ccfe868ad1d5 (patch) | |
| tree | 6a8e7a6e3586bc0f679b82d5ec3ba791741cb842 /src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java | |
| parent | d15781a946d797a35fb00c248a3e57e2aa3414b5 (diff) | |
| download | RoughlyEnoughItems-0710ab56e7e8f76670dab785b907ccfe868ad1d5.tar.gz RoughlyEnoughItems-0710ab56e7e8f76670dab785b907ccfe868ad1d5.tar.bz2 RoughlyEnoughItems-0710ab56e7e8f76670dab785b907ccfe868ad1d5.zip | |
3.2.9
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.java | 59 |
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); } } |
