From b4be45e414504afb49910d766bebcd00f55b052b Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 16 Jan 2020 16:10:19 +0800 Subject: 3.3.11 --- .../me/shedaniel/rei/gui/widget/LabelWidget.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java') 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 ac6815d3d..bd9acb417 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java @@ -12,6 +12,9 @@ import net.minecraft.client.gui.Element; import java.util.Collections; import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Supplier; public class LabelWidget extends WidgetWithBounds { @@ -20,18 +23,33 @@ public class LabelWidget extends WidgetWithBounds { private int defaultColor; private boolean hasShadows = true; private boolean centered = true; + private Supplier tooltipSupplier; @Deprecated public LabelWidget(int x, int y, String text) { this(new Point(x, y), text); } + @Deprecated public LabelWidget(Point point, String text) { this.pos = point; this.text = text; this.defaultColor = ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : -1; } + public static LabelWidget create(Point point, String text) { + return new LabelWidget(point, text); + } + + public static ClickableLabelWidget createClickable(Point point, String text, Consumer onClicked) { + return new ClickableActionedLabelWidget(point, text, onClicked); + } + + public LabelWidget tooltip(Supplier tooltipSupplier) { + this.tooltipSupplier = tooltipSupplier; + return this; + } + public boolean isCentered() { return centered; } @@ -94,6 +112,10 @@ public class LabelWidget extends WidgetWithBounds { return this; } + public Optional getTooltips() { + return Optional.ofNullable(tooltipSupplier).map(Supplier::get); + } + @Override public Rectangle getBounds() { int width = font.getStringWidth(text); @@ -125,4 +147,9 @@ public class LabelWidget extends WidgetWithBounds { } } + protected void drawTooltips(int mouseX, int mouseY) { + if (getTooltips().isPresent()) + if (containsMouse(mouseX, mouseY)) + ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(getTooltips().get().split("\n"))); + } } -- cgit