Skip to content

Commit a7c1b56

Browse files
committed
fix some focus issues with the search box
1 parent e441260 commit a7c1b56

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/VideoSettingsScreen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.io.IOException;
3333
import java.time.Instant;
3434
import java.time.temporal.ChronoUnit;
35-
import java.util.ArrayList;
3635
import java.util.Iterator;
3736
import java.util.List;
3837
import java.util.stream.Stream;
@@ -302,6 +301,12 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
302301
return true;
303302
}
304303

304+
// TODO: switching between the search and the regular mode breaks the keyboard focus
305+
if (this.getFocused() == this.pageList && this.controlList == this.searchWidget ||
306+
this.getFocused() == this.searchWidget && this.controlList == this.optionList) {
307+
this.setFocused(this.controlList);
308+
}
309+
305310
return true;
306311
}
307312

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/AbstractParentWidget.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public GuiEventListener getFocused() {
7575

7676
@Override
7777
public void setFocused(@Nullable GuiEventListener guiEventListener) {
78+
if (this.focusedElement != null) {
79+
this.focusedElement.setFocused(false);
80+
}
81+
82+
if (guiEventListener != null) {
83+
guiEventListener.setFocused(true);
84+
}
85+
7886
this.focusedElement = guiEventListener;
7987
}
8088

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
7474
this.drawRect(graphics, this.getX(), this.getLimitY() - 1, this.getLimitX(), this.getLimitY(), Colors.THEME);
7575
}
7676

77-
if (this.drawFrame) {
77+
if (this.drawFrame || this.enabled && this.isFocused()) {
7878
this.drawBorder(graphics, this.getX(), this.getY(), this.getLimitX(), this.getLimitY(), Colors.BUTTON_BORDER);
7979
}
8080
}

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/ScrollbarWidget.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import net.caffeinemc.mods.sodium.api.util.ColorABGR;
44
import net.caffeinemc.mods.sodium.client.util.Dim2i;
5+
import net.minecraft.client.gui.ComponentPath;
56
import net.minecraft.client.gui.GuiGraphics;
67
import net.minecraft.client.gui.narration.NarrationElementOutput;
8+
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
79
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
811

9-
// TODO: override some methods to make it not focusable?
1012
public class ScrollbarWidget extends AbstractWidget {
1113
private static final int COLOR = ColorABGR.pack(50, 50, 50, 150);
1214
private static final int HIGHLIGHT_COLOR = ColorABGR.pack(100, 100, 100, 150);
@@ -140,5 +142,11 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del
140142

141143
@Override
142144
public void updateNarration(NarrationElementOutput builder) {
145+
// no narration
146+
}
147+
148+
@Override
149+
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent event) {
150+
return null;
143151
}
144152
}

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/SearchWidget.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ private void rebuild() {
6767
if (!this.searchBox.getValue().equals(this.query)) {
6868
this.searchBox.setValue(this.query);
6969
}
70-
this.searchBox.setFocused(true);
70+
71+
this.setFocused(this.searchBox);
7172

7273
var headerHeight = this.searchBox.getBottom() + Layout.INNER_MARGIN;
7374
if (this.scrollbar == null) {
@@ -103,8 +104,8 @@ private void rebuild() {
103104
if (lastSource == null || lastSource.getPage() != page) {
104105
if (lastSource != null && !trailingSpace) {
105106
listHeight += Layout.INNER_MARGIN;
106-
trailingSpace = true;
107107
}
108+
108109
pageListHeight = listHeight = Math.max(pageListHeight, listHeight);
109110

110111
if (lastSource == null || lastSource.getModOptions() != modOptions) {

0 commit comments

Comments
 (0)