diff options
author | xander <xander@isxander.dev> | 2022-09-22 19:45:00 +0100 |
---|---|---|
committer | xander <xander@isxander.dev> | 2022-09-22 19:45:00 +0100 |
commit | f77914f74903164c34bf44bfbe4c298da87e1e32 (patch) | |
tree | 7a0d0a9d496c0642186b9a848ea39279e4f8cdcb /src | |
parent | 36891bb4f9e6aedacf8f79bc1b18b0402845f3a8 (diff) | |
download | YetAnotherConfigLib-f77914f74903164c34bf44bfbe4c298da87e1e32.tar.gz YetAnotherConfigLib-f77914f74903164c34bf44bfbe4c298da87e1e32.tar.bz2 YetAnotherConfigLib-f77914f74903164c34bf44bfbe4c298da87e1e32.zip |
1.4.3
Cache search query results for huge performance gains
Allow some `StringControllerElement` methods to be inheritable
Diffstat (limited to 'src')
3 files changed, 25 insertions, 13 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java index 7789520..4adb30b 100644 --- a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -26,6 +26,8 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> private final YACLScreen yaclScreen; private boolean singleCategory = false; + private ImmutableList<Entry> viewableChildren; + public OptionListWidget(YACLScreen screen, MinecraftClient client, int width, int height) { super(client, width / 3 * 2, height, 0, height, 22); this.yaclScreen = screen; @@ -71,6 +73,7 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> } } + recacheViewableChildren(); setScrollAmount(0); } @@ -203,9 +206,13 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> fill(matrices, left, top, right, bottom, 0x6B000000); } + public void recacheViewableChildren() { + this.viewableChildren = ImmutableList.copyOf(super.children().stream().filter(Entry::isViewable).toList()); + } + @Override public List<Entry> children() { - return super.children().stream().filter(Entry::isViewable).toList(); + return viewableChildren; } public abstract class Entry extends ElementListWidget.Entry<Entry> { @@ -322,6 +329,7 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry> this.groupExpanded = !group.collapsed(); this.expandMinimizeButton = new LowProfileButtonWidget(0, 0, 20, 20, Text.empty(), btn -> { setExpanded(!isExpanded()); + recacheViewableChildren(); }); updateExpandMinimizeText(); } diff --git a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java index 1f0f49b..b4834db 100644 --- a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java @@ -31,19 +31,15 @@ public class SearchFieldWidget extends TextFieldWidget { @Override public void write(String text) { update(); - super.write(text); - - isEmpty = getText().isEmpty(); + postUpdate(); } @Override public void eraseCharacters(int characterOffset) { update(); - super.eraseCharacters(characterOffset); - - isEmpty = getText().isEmpty(); + postUpdate(); } private void update() { @@ -56,6 +52,11 @@ public class SearchFieldWidget extends TextFieldWidget { } } + private void postUpdate() { + isEmpty = getText().isEmpty(); + yaclScreen.optionList.recacheViewableChildren(); + } + public boolean isEmpty() { return isEmpty; } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java index dd977f7..4a0061b 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java @@ -119,19 +119,22 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< return super.isMouseOver(mouseX, mouseY) || mouseDown; } - private void setValueFromMouse(double mouseX) { + protected void setValueFromMouse(double mouseX) { double value = (mouseX - sliderBounds.x()) / sliderBounds.width() * control.range(); - double roundedValue = MathHelper.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping - control.setPendingValue(roundedValue); + control.setPendingValue(roundToInterval(value)); calculateInterpolation(); } + protected double roundToInterval(double value) { + return MathHelper.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping + } + @Override protected int getHoveredControlWidth() { return sliderBounds.width() + getUnhoveredControlWidth() + 6 + getThumbWidth() / 2; } - private void calculateInterpolation() { + protected void calculateInterpolation() { interpolation = (float) ((control.pendingValue() - control.min()) * 1 / control.range()); } @@ -141,11 +144,11 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< sliderBounds = Dimension.ofInt(dim.xLimit() - getXPadding() - getThumbWidth() / 2 - dim.width() / 3, dim.centerY() - 5, dim.width() / 3, 10); } - private int getThumbX() { + protected int getThumbX() { return (int) (sliderBounds.x() + sliderBounds.width() * interpolation); } - private int getThumbWidth() { + protected int getThumbWidth() { return 4; } |