diff options
author | isXander <xandersmith2008@gmail.com> | 2022-12-06 22:08:07 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2022-12-06 22:08:07 +0000 |
commit | 3f93f5cb0b30268ad76b5fe59c00c6af7286686a (patch) | |
tree | 25eefed38ca4711c4937e4838cbbc9b769c04c2c /src/client/java/dev/isxander | |
parent | daf3168671bc9c0cd64693d7129cddfdb1a08bb2 (diff) | |
download | YetAnotherConfigLib-3f93f5cb0b30268ad76b5fe59c00c6af7286686a.tar.gz YetAnotherConfigLib-3f93f5cb0b30268ad76b5fe59c00c6af7286686a.tar.bz2 YetAnotherConfigLib-3f93f5cb0b30268ad76b5fe59c00c6af7286686a.zip |
minor string controller element improvements
Better carot positioning when clicking in text fields
Fix left arrow not working in color controller
rc3
bump LQF
Diffstat (limited to 'src/client/java/dev/isxander')
8 files changed, 40 insertions, 16 deletions
diff --git a/src/client/java/dev/isxander/yacl/api/OptionFlag.java b/src/client/java/dev/isxander/yacl/api/OptionFlag.java index 203a674..7a5c23f 100644 --- a/src/client/java/dev/isxander/yacl/api/OptionFlag.java +++ b/src/client/java/dev/isxander/yacl/api/OptionFlag.java @@ -11,14 +11,10 @@ import java.util.function.Consumer; */ @FunctionalInterface public interface OptionFlag extends Consumer<MinecraftClient> { - /** - * Warns the user that a game restart is required for the changes to take effect - */ + /** Warns the user that a game restart is required for the changes to take effect */ OptionFlag GAME_RESTART = client -> client.setScreen(new RequireRestartScreen(client.currentScreen)); - /** - * Reloads chunks upon applying (F3+A) - */ + /** Reloads chunks upon applying (F3+A) */ OptionFlag RELOAD_CHUNKS = client -> client.worldRenderer.reload(); OptionFlag WORLD_RENDER_UPDATE = client -> client.worldRenderer.scheduleTerrainUpdate(); diff --git a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java index 785f4e2..7ea275b 100644 --- a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -317,7 +317,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } private void updateExpandMinimizeText() { - expandMinimizeButton.setMessage(Text.of(isExpanded() ? "\u25BC" : "\u25B6")); + expandMinimizeButton.setMessage(Text.of(isExpanded() ? "▼" : "▶")); } public void setOptionEntries(List<OptionEntry> optionEntries) { diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java b/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java index 6853a03..b8e1942 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java @@ -183,11 +183,13 @@ public class ColorController implements IStringController<Color> { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + int prevSelectionLength = selectionLength; + selectionLength = 0; if (super.keyPressed(keyCode, scanCode, modifiers)) { caretPos = Math.max(1, caretPos); setSelectionLength(); return true; - } + } else selectionLength = prevSelectionLength; return false; } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java index bce6906..47a4c96 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java @@ -41,7 +41,7 @@ public class StringControllerElement extends ControllerWidget<IStringController< protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { ticks += delta; - String text = instantApply ? control.getString() : inputField; + String text = getValueText().getString(); DrawableHelper.fill(matrices, inputFieldBounds.x(), inputFieldBounds.yLimit(), inputFieldBounds.xLimit(), inputFieldBounds.yLimit() + 1, -1); DrawableHelper.fill(matrices, inputFieldBounds.x() + 1, inputFieldBounds.yLimit() + 1, inputFieldBounds.xLimit() + 1, inputFieldBounds.yLimit() + 2, 0xFF404040); @@ -64,13 +64,29 @@ public class StringControllerElement extends ControllerWidget<IStringController< @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (isAvailable() && inputFieldBounds.isPointInside((int) mouseX, (int) mouseY)) { - if (!inputFieldFocused) { - inputFieldFocused = true; + if (isAvailable() && getDimension().isPointInside((int) mouseX, (int) mouseY)) { + inputFieldFocused = true; + + if (!inputFieldBounds.isPointInside((int) mouseX, (int) mouseY)) { caretPos = getDefaultCarotPos(); } else { - int textWidth = (int) mouseX - inputFieldBounds.x(); - caretPos = textRenderer.trimToWidth(control.getString(), textWidth).length(); + // gets the appropriate carot position for where you click + int textX = (int) mouseX - inputFieldBounds.x(); + int pos = -1; + int currentWidth = 0; + for (char ch : inputField.toCharArray()) { + pos++; + int charLength = textRenderer.getWidth(String.valueOf(ch)); + if (currentWidth + charLength / 2 > textX) { // if more than half way past the characters select in front of that char + caretPos = pos; + break; + } else if (pos == inputField.length() - 1) { + // if we have reached the end and no matches, it must be the second half of the char so the last position + caretPos = pos + 1; + } + currentWidth += charLength; + } + selectionLength = 0; } return true; diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java index 1dbd7c0..8933df3 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java @@ -84,7 +84,7 @@ public class DoubleFieldController extends NumberFieldController<Double> { */ @Override public String getString() { - return BigDecimal.valueOf(option().pendingValue()).stripTrailingZeros().toPlainString(); + return String.valueOf(option().pendingValue()); } /** diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java index 4b34d7f..b1eb3a2 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java @@ -84,7 +84,7 @@ public class FloatFieldController extends NumberFieldController<Float> { */ @Override public String getString() { - return BigDecimal.valueOf(option().pendingValue()).stripTrailingZeros().toPlainString(); + return String.valueOf(option().pendingValue()); } /** diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java index 5f0121a..50eecec 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java @@ -62,6 +62,11 @@ public class IntegerFieldController extends NumberFieldController<Integer> { this(option, -Integer.MAX_VALUE, Integer.MAX_VALUE, IntegerSliderController.DEFAULT_FORMATTER); } + @Override + public boolean isInputValid(String input) { + return input.matches("\\d+|-|"); + } + /** * {@inheritDoc} */ diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java index 713d39f..516de74 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java @@ -62,6 +62,11 @@ public class LongFieldController extends NumberFieldController<Long> { this(option, -Long.MAX_VALUE, Long.MAX_VALUE, LongSliderController.DEFAULT_FORMATTER); } + @Override + public boolean isInputValid(String input) { + return input.matches("\\d+|-|"); + } + /** * {@inheritDoc} */ |