aboutsummaryrefslogtreecommitdiff
path: root/src/client/java
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-03-29 17:11:24 +0100
committerisXander <xandersmith2008@gmail.com>2023-03-29 17:11:24 +0100
commitc5917e9854958adf1e4aa1aa22251f7b3f911d38 (patch)
treea6d9a9c37dc69e92ec8ce0bf9e03b2a0d3a502d8 /src/client/java
parentc02229186aa13b1d699e2d00d24865260f158a54 (diff)
downloadYetAnotherConfigLib-c5917e9854958adf1e4aa1aa22251f7b3f911d38.tar.gz
YetAnotherConfigLib-c5917e9854958adf1e4aa1aa22251f7b3f911d38.tar.bz2
YetAnotherConfigLib-c5917e9854958adf1e4aa1aa22251f7b3f911d38.zip
Fix buttons stuck focusing after clicking the mouse.
Diffstat (limited to 'src/client/java')
-rw-r--r--src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java12
-rw-r--r--src/client/java/dev/isxander/yacl/gui/OptionListWidget.java7
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java2
3 files changed, 20 insertions, 1 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
index e28509e..07f5635 100644
--- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
+++ b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java
@@ -3,6 +3,7 @@ package dev.isxander.yacl.gui;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
+import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.Nullable;
@@ -92,6 +93,17 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
return null;
}
+ @Override
+ public boolean mouseReleased(double mouseX, double mouseY, int button) {
+ // on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus
+ boolean clicked = super.mouseReleased(mouseX, mouseY, button);
+ if (getFocused() != null) {
+ this.getFocused().setFocused(null);
+ this.setFocused(null);
+ }
+ return clicked;
+ }
+
/*
below code is licensed from cloth-config under LGPL3
modified to inherit vanilla's EntryListWidget and use yarn mappings
diff --git a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java
index 097f076..333d67c 100644
--- a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java
+++ b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java
@@ -150,6 +150,13 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr
}
@Override
+ public void mouseMoved(double mouseX, double mouseY) {
+ if (getFocused() instanceof OptionEntry optionEntry)
+ optionEntry.widget.unfocus();
+ setFocused(null);
+ }
+
+ @Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
super.mouseScrolled(mouseX, mouseY, amount);
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java b/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java
index d97b418..d7d17d5 100644
--- a/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java
+++ b/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java
@@ -142,7 +142,7 @@ public class BooleanController implements Controller<Boolean> {
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
- if (!focused) {
+ if (!isFocused()) {
return false;
}