From f77914f74903164c34bf44bfbe4c298da87e1e32 Mon Sep 17 00:00:00 2001 From: xander Date: Thu, 22 Sep 2022 19:45:00 +0100 Subject: 1.4.3 Cache search query results for huge performance gains Allow some `StringControllerElement` methods to be inheritable --- src/main/java/dev/isxander/yacl/gui/OptionListWidget.java | 10 +++++++++- .../java/dev/isxander/yacl/gui/SearchFieldWidget.java | 13 +++++++------ .../gui/controllers/slider/SliderControllerElement.java | 15 +++++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) (limited to 'src/main/java/dev/isxander/yacl') 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 private final YACLScreen yaclScreen; private boolean singleCategory = false; + private ImmutableList 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 } } + recacheViewableChildren(); setScrollAmount(0); } @@ -203,9 +206,13 @@ public class OptionListWidget extends ElementListWidget fill(matrices, left, top, right, bottom, 0x6B000000); } + public void recacheViewableChildren() { + this.viewableChildren = ImmutableList.copyOf(super.children().stream().filter(Entry::isViewable).toList()); + } + @Override public List children() { - return super.children().stream().filter(Entry::isViewable).toList(); + return viewableChildren; } public abstract class Entry extends ElementListWidget.Entry { @@ -322,6 +329,7 @@ public class OptionListWidget extends ElementListWidget 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