Skip to content

Commit

Permalink
Added option to not reset tooltip time on button press.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Apr 12, 2024
1 parent 9ed6604 commit 512050d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/codechicken/lib/gui/modular/elements/GuiButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class GuiButton extends GuiElement<GuiButton> {
private Supplier<Boolean> disabled = () -> false;
private Supplier<Boolean> 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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 512050d

Please sign in to comment.