Skip to content

Commit e441260

Browse files
committed
add search results with page list and clickable page list items
1 parent b63bea6 commit e441260

File tree

5 files changed

+277
-29
lines changed

5 files changed

+277
-29
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
// TODO: add button or some other way for user to reset a specific option, all options on a page, and all options of a mod to their default values (not just "reset" changes, but reset to default value)
4646
// TODO: make RD option respect Vanilla's >16 RD only allowed if memory >1GB constraint
4747
public class VideoSettingsScreen extends Screen implements ScreenPromptable {
48-
private final List<ControlElement> controls = new ArrayList<>();
49-
5048
private final Screen prevScreen;
5149

5250
private ModOptions currentMod;
@@ -146,6 +144,7 @@ public void setPage(ModOptions modOptions, OptionPage page) {
146144
this.currentPage = page;
147145
this.rebuildOptionList();
148146
}
147+
this.pageList.switchSelected(modOptions, page);
149148
}
150149

151150
@Override
@@ -160,8 +159,6 @@ protected void init() {
160159
}
161160

162161
private void rebuild() {
163-
this.controls.clear();
164-
165162
this.clearWidgets();
166163

167164
// find the first non-external page
@@ -203,6 +200,10 @@ private void rebuild() {
203200
this.addRenderableWidget(this.undoButton);
204201
this.addRenderableWidget(this.applyButton);
205202
this.addRenderableWidget(this.closeButton);
203+
204+
if (this.searchWidget != null) {
205+
this.startSearch(this.searchWidget);
206+
}
206207
}
207208

208209
private void rebuildOptionList() {
@@ -381,7 +382,11 @@ public ScreenPrompt getPrompt() {
381382
}
382383

383384
private void startSearch() {
384-
this.searchWidget = new SearchWidget(this::closeSearch, new Dim2i(0, 0, Layout.PAGE_LIST_WIDTH + Layout.INNER_MARGIN + Layout.OPTION_WIDTH + Layout.OPTION_LIST_SCROLLBAR_OFFSET + Layout.SCROLLBAR_WIDTH, this.height));
385+
this.startSearch(null);
386+
}
387+
388+
private void startSearch(@Nullable SearchWidget old) {
389+
this.searchWidget = new SearchWidget(this, this::closeSearch, old, new Dim2i(0, 0, Layout.PAGE_LIST_WIDTH + Layout.INNER_MARGIN + Layout.OPTION_WIDTH, this.height));
385390
this.addRenderableWidget(this.searchWidget);
386391

387392
this.removeWidget(this.pageList);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
6161
}
6262

6363
if (this.subtitle == null) {
64-
this.drawString(graphics, this.truncateToFitWidth(this.label), x1 + Layout.TEXT_LEFT_PADDING, (int) Math.ceil(((y1 + (this.getHeight() - this.font.lineHeight) * 0.5f))), textColor);
64+
this.drawString(graphics, this.truncateToFitWidth(this.label), x1 + Layout.TEXT_LEFT_PADDING, (int) Math.ceil(((y1 + (this.getTextBoxHeight() - this.font.lineHeight) * 0.5f))), textColor);
6565
} else {
66-
var center = y1 + this.getHeight() * 0.5f;
66+
var center = y1 + this.getTextBoxHeight() * 0.5f;
6767
this.drawString(graphics, this.truncateToFitWidth(this.label), x1 + Layout.TEXT_LEFT_PADDING, (int) Math.ceil(center - (this.font.lineHeight + Layout.TEXT_LINE_SPACING * 0.5f)), textColor);
6868
this.drawString(graphics, this.truncateToFitWidth(this.subtitle), x1 + Layout.TEXT_LEFT_PADDING, (int) Math.ceil(center + Layout.TEXT_LINE_SPACING * 0.5f), textColor);
6969
}
@@ -73,6 +73,10 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
7373
}
7474
}
7575

76+
protected int getTextBoxHeight() {
77+
return this.getHeight();
78+
}
79+
7680
private String truncateToFitWidth(Component text) {
7781
return this.truncateTextToFit(text.getString(), this.getWidth() - 14);
7882
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private void rebuild(Screen screen) {
3333
this.clearChildren();
3434
this.scrollbar = this.addRenderableChild(new ScrollbarWidget(new Dim2i(x + width + Layout.OPTION_LIST_SCROLLBAR_OFFSET, y, Layout.SCROLLBAR_WIDTH, height)));
3535

36-
int entryHeight = 18;
36+
int entryHeight = this.font.lineHeight * 2;
3737
int listHeight = 0;
3838
for (OptionGroup group : this.page.groups()) {
3939
// Add each option's control element

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,18 @@ private void rebuild() {
8282

8383
@Override
8484
public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float delta) {
85-
graphics.fillGradient(this.getX(), this.getY(), this.getLimitX(), this.getLimitY(), Colors.BACKGROUND_LIGHT, Colors.BACKGROUND_DEFAULT);
85+
renderBackgroundGradient(graphics, this.getX(), this.getY(), this.getLimitX(), this.getLimitY());
8686
graphics.enableScissor(this.getX(), this.search.getLimitY(), this.getLimitX(), this.getLimitY());
8787
super.render(graphics, mouseX, mouseY, delta);
8888
graphics.disableScissor();
8989

90-
// this.verticalScrollScissorGradient(graphics, scissorEnd);
91-
9290
this.search.render(graphics, mouseX, mouseY, delta);
9391
}
9492

93+
public static void renderBackgroundGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2) {
94+
graphics.fillGradient(x1, y1, x2, y2, Colors.BACKGROUND_LIGHT, Colors.BACKGROUND_DEFAULT);
95+
}
96+
9597
@Override
9698
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
9799
this.scrollbar.scroll((int) (-verticalAmount * 10));
@@ -106,6 +108,17 @@ private void switchSelected(CenteredFlatWidget widget) {
106108
this.selected.setSelected(true);
107109
}
108110

111+
public void switchSelected(ModOptions modOptions, Page page) {
112+
for (var child : this.children()) {
113+
if (child instanceof PageEntryWidget pageEntryWidget) {
114+
if (pageEntryWidget.page == page && pageEntryWidget.modOptions == modOptions) {
115+
this.switchSelected(pageEntryWidget);
116+
return;
117+
}
118+
}
119+
}
120+
}
121+
109122
private class EntryWidget extends CenteredFlatWidget {
110123
EntryWidget(Dim2i dim, Component label, boolean isSelectable, ColorTheme theme) {
111124
super(dim, label, isSelectable, theme);

0 commit comments

Comments
 (0)