From 512050d0580e1f223f25824c3c1a4bb671308266 Mon Sep 17 00:00:00 2001 From: brandon3055 Date: Sat, 13 Apr 2024 05:46:23 +1000 Subject: [PATCH] Added option to not reset tooltip time on button press. --- .../lib/gui/modular/elements/GuiButton.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java index b8df4d2b..2f291833 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java @@ -35,6 +35,7 @@ public class GuiButton extends GuiElement { private Supplier disabled = () -> false; private Supplier toggleState; private GuiText label = null; + private boolean resetHoverOnPress = true; /** * In its default state this is a blank, invisible element that can fire callbacks when pressed. @@ -164,6 +165,15 @@ public GuiText getLabel() { return label; } + /** + * By default, hover time is reset when button is pressed. + * THis allows you to disable that functionality to the tooltip will remain open when button is pressed. + */ + public GuiButton setResetHoverOnPress(boolean resetHoverOnPress) { + this.resetHoverOnPress = resetHoverOnPress; + return this; + } + /** * This event is fired immediately when this button is left-clicked. * This is the logic used by most vanilla gui buttons. @@ -294,7 +304,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { Runnable onPress = this.onPress.get(button); if (onClick == null && onPress == null) return false; pressed = true; - hoverTime = 1; + if (resetHoverOnPress) hoverTime = 1; boolean consume = false; if (onClick != null) { @@ -318,7 +328,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button, boolean c Runnable onClick = this.onClick.get(button); Runnable onPress = this.onPress.get(button); if (onClick == null && onPress == null) return consumed; - hoverTime = 1; + if (resetHoverOnPress) hoverTime = 1; if (!isDisabled() && isMouseOver()) { if (pressed && onPress != null) {