Skip to content

Commit 512050d

Browse files
committed
Added option to not reset tooltip time on button press.
1 parent 9ed6604 commit 512050d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class GuiButton extends GuiElement<GuiButton> {
3535
private Supplier<Boolean> disabled = () -> false;
3636
private Supplier<Boolean> toggleState;
3737
private GuiText label = null;
38+
private boolean resetHoverOnPress = true;
3839

3940
/**
4041
* In its default state this is a blank, invisible element that can fire callbacks when pressed.
@@ -164,6 +165,15 @@ public GuiText getLabel() {
164165
return label;
165166
}
166167

168+
/**
169+
* By default, hover time is reset when button is pressed.
170+
* THis allows you to disable that functionality to the tooltip will remain open when button is pressed.
171+
*/
172+
public GuiButton setResetHoverOnPress(boolean resetHoverOnPress) {
173+
this.resetHoverOnPress = resetHoverOnPress;
174+
return this;
175+
}
176+
167177
/**
168178
* This event is fired immediately when this button is left-clicked.
169179
* This is the logic used by most vanilla gui buttons.
@@ -294,7 +304,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
294304
Runnable onPress = this.onPress.get(button);
295305
if (onClick == null && onPress == null) return false;
296306
pressed = true;
297-
hoverTime = 1;
307+
if (resetHoverOnPress) hoverTime = 1;
298308

299309
boolean consume = false;
300310
if (onClick != null) {
@@ -318,7 +328,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button, boolean c
318328
Runnable onClick = this.onClick.get(button);
319329
Runnable onPress = this.onPress.get(button);
320330
if (onClick == null && onPress == null) return consumed;
321-
hoverTime = 1;
331+
if (resetHoverOnPress) hoverTime = 1;
322332

323333
if (!isDisabled() && isMouseOver()) {
324334
if (pressed && onPress != null) {

0 commit comments

Comments
 (0)