Skip to content

Commit c5917e9

Browse files
committed
Fix buttons stuck focusing after clicking the mouse.
1 parent c022291 commit c5917e9

5 files changed

Lines changed: 22 additions & 2 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
val ciRun = System.getenv().containsKey("GITHUB_ACTIONS")
1717

1818
group = "dev.isxander"
19-
version = "2.3.0"
19+
version = "2.3.1"
2020

2121
if (ciRun)
2222
version = "$version+${grgit.branch.current().name.replace('/', '.')}-SNAPSHOT"

changelogs/2.3.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix buttons stuck focusing after clicking the mouse.

src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mojang.blaze3d.vertex.PoseStack;
44
import net.minecraft.client.Minecraft;
55
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
6+
import net.minecraft.client.gui.components.events.GuiEventListener;
67
import net.minecraft.util.Mth;
78
import org.jetbrains.annotations.Nullable;
89

@@ -92,6 +93,17 @@ protected E getEntryAtPosition(double x, double y) {
9293
return null;
9394
}
9495

96+
@Override
97+
public boolean mouseReleased(double mouseX, double mouseY, int button) {
98+
// on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus
99+
boolean clicked = super.mouseReleased(mouseX, mouseY, button);
100+
if (getFocused() != null) {
101+
this.getFocused().setFocused(null);
102+
this.setFocused(null);
103+
}
104+
return clicked;
105+
}
106+
95107
/*
96108
below code is licensed from cloth-config under LGPL3
97109
modified to inherit vanilla's EntryListWidget and use yarn mappings

src/client/java/dev/isxander/yacl/gui/OptionListWidget.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
149149
return super.mouseClicked(mouseX, mouseY, button);
150150
}
151151

152+
@Override
153+
public void mouseMoved(double mouseX, double mouseY) {
154+
if (getFocused() instanceof OptionEntry optionEntry)
155+
optionEntry.widget.unfocus();
156+
setFocused(null);
157+
}
158+
152159
@Override
153160
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
154161
super.mouseScrolled(mouseX, mouseY, amount);

src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected Component getValueText() {
142142

143143
@Override
144144
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
145-
if (!focused) {
145+
if (!isFocused()) {
146146
return false;
147147
}
148148

0 commit comments

Comments
 (0)