Skip to content

Commit f77914f

Browse files
committed
1.4.3
Cache search query results for huge performance gains Allow some `StringControllerElement` methods to be inheritable
1 parent 36891bb commit f77914f

5 files changed

Lines changed: 28 additions & 14 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 = "1.4.2"
19+
version = "1.4.3"
2020

2121
if (ciRun)
2222
version = "$version-SNAPSHOT"

changelogs/1.4.3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Cache search query results for huge performance gains
2+
- Allow some `StringControllerElement` methods to be inheritable

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
2626
private final YACLScreen yaclScreen;
2727
private boolean singleCategory = false;
2828

29+
private ImmutableList<Entry> viewableChildren;
30+
2931
public OptionListWidget(YACLScreen screen, MinecraftClient client, int width, int height) {
3032
super(client, width / 3 * 2, height, 0, height, 22);
3133
this.yaclScreen = screen;
@@ -71,6 +73,7 @@ public void refreshOptions() {
7173
}
7274
}
7375

76+
recacheViewableChildren();
7477
setScrollAmount(0);
7578
}
7679

@@ -203,9 +206,13 @@ protected void renderBackground(MatrixStack matrices) {
203206
fill(matrices, left, top, right, bottom, 0x6B000000);
204207
}
205208

209+
public void recacheViewableChildren() {
210+
this.viewableChildren = ImmutableList.copyOf(super.children().stream().filter(Entry::isViewable).toList());
211+
}
212+
206213
@Override
207214
public List<Entry> children() {
208-
return super.children().stream().filter(Entry::isViewable).toList();
215+
return viewableChildren;
209216
}
210217

211218
public abstract class Entry extends ElementListWidget.Entry<Entry> {
@@ -322,6 +329,7 @@ private GroupSeparatorEntry(OptionGroup group, Screen screen) {
322329
this.groupExpanded = !group.collapsed();
323330
this.expandMinimizeButton = new LowProfileButtonWidget(0, 0, 20, 20, Text.empty(), btn -> {
324331
setExpanded(!isExpanded());
332+
recacheViewableChildren();
325333
});
326334
updateExpandMinimizeText();
327335
}

src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float del
3131
@Override
3232
public void write(String text) {
3333
update();
34-
3534
super.write(text);
36-
37-
isEmpty = getText().isEmpty();
35+
postUpdate();
3836
}
3937

4038
@Override
4139
public void eraseCharacters(int characterOffset) {
4240
update();
43-
4441
super.eraseCharacters(characterOffset);
45-
46-
isEmpty = getText().isEmpty();
42+
postUpdate();
4743
}
4844

4945
private void update() {
@@ -56,6 +52,11 @@ private void update() {
5652
}
5753
}
5854

55+
private void postUpdate() {
56+
isEmpty = getText().isEmpty();
57+
yaclScreen.optionList.recacheViewableChildren();
58+
}
59+
5960
public boolean isEmpty() {
6061
return isEmpty;
6162
}

src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,22 @@ public boolean isMouseOver(double mouseX, double mouseY) {
119119
return super.isMouseOver(mouseX, mouseY) || mouseDown;
120120
}
121121

122-
private void setValueFromMouse(double mouseX) {
122+
protected void setValueFromMouse(double mouseX) {
123123
double value = (mouseX - sliderBounds.x()) / sliderBounds.width() * control.range();
124-
double roundedValue = MathHelper.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping
125-
control.setPendingValue(roundedValue);
124+
control.setPendingValue(roundToInterval(value));
126125
calculateInterpolation();
127126
}
128127

128+
protected double roundToInterval(double value) {
129+
return MathHelper.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping
130+
}
131+
129132
@Override
130133
protected int getHoveredControlWidth() {
131134
return sliderBounds.width() + getUnhoveredControlWidth() + 6 + getThumbWidth() / 2;
132135
}
133136

134-
private void calculateInterpolation() {
137+
protected void calculateInterpolation() {
135138
interpolation = (float) ((control.pendingValue() - control.min()) * 1 / control.range());
136139
}
137140

@@ -141,11 +144,11 @@ public void setDimension(Dimension<Integer> dim) {
141144
sliderBounds = Dimension.ofInt(dim.xLimit() - getXPadding() - getThumbWidth() / 2 - dim.width() / 3, dim.centerY() - 5, dim.width() / 3, 10);
142145
}
143146

144-
private int getThumbX() {
147+
protected int getThumbX() {
145148
return (int) (sliderBounds.x() + sliderBounds.width() * interpolation);
146149
}
147150

148-
private int getThumbWidth() {
151+
protected int getThumbWidth() {
149152
return 4;
150153
}
151154

0 commit comments

Comments
 (0)