diff options
author | xander <xander@isxander.dev> | 2022-09-10 13:44:34 +0100 |
---|---|---|
committer | xander <xander@isxander.dev> | 2022-09-10 19:09:09 +0100 |
commit | c72f2d573ba425871642f2c5b98e7630c10c30fd (patch) | |
tree | fe49b0a499c5529f7588a0331261c86547d92e47 /src/main/java/dev/isxander/yacl/gui/controllers/string | |
parent | 3569199680de4c2a9635676bb9217c122b5e2d1b (diff) | |
download | YetAnotherConfigLib-c72f2d573ba425871642f2c5b98e7630c10c30fd.tar.gz YetAnotherConfigLib-c72f2d573ba425871642f2c5b98e7630c10c30fd.tar.bz2 YetAnotherConfigLib-c72f2d573ba425871642f2c5b98e7630c10c30fd.zip |
input field improvements
you can now escape out with `ESC`
fix selection highlight not matching up with the color controller
consume actions
Diffstat (limited to 'src/main/java/dev/isxander/yacl/gui/controllers/string')
-rw-r--r-- | src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java index 9b549bc..c606d69 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java @@ -48,7 +48,7 @@ public class StringControllerElement extends ControllerWidget<IStringController< } if (selectionLength != 0) { - int selectionX = inputFieldBounds.x() + textRenderer.getWidth(inputField.substring(0, caretPos + selectionLength)); + int selectionX = inputFieldBounds.x() + textRenderer.getWidth(control.getString().substring(0, caretPos + selectionLength)); DrawableHelper.fill(matrices, caretX, inputFieldBounds.y() - 1, selectionX, inputFieldBounds.yLimit(), 0x803030FF); } } @@ -83,6 +83,10 @@ public class StringControllerElement extends ControllerWidget<IStringController< return false; switch (keyCode) { + case GLFW.GLFW_KEY_ESCAPE -> { + inputFieldFocused = false; + return true; + } case GLFW.GLFW_KEY_LEFT -> { if (Screen.hasShiftDown()) { if (Screen.hasControlDown()) { @@ -132,14 +136,18 @@ public class StringControllerElement extends ControllerWidget<IStringController< if (canUseShortcuts()) { if (Screen.isPaste(keyCode)) { this.write(client.keyboard.getClipboard()); + return true; } else if (Screen.isCopy(keyCode) && selectionLength != 0) { client.keyboard.setClipboard(getSelection()); + return true; } else if (Screen.isCut(keyCode) && selectionLength != 0) { client.keyboard.setClipboard(getSelection()); this.write(""); + return true; } else if (Screen.isSelectAll(keyCode)) { caretPos = inputField.length(); selectionLength = -caretPos; + return true; } } @@ -166,6 +174,7 @@ public class StringControllerElement extends ControllerWidget<IStringController< } else if (caretPos > 0) { inputField.deleteCharAt(caretPos - 1); caretPos--; + updateControl(); } } @@ -228,7 +237,6 @@ public class StringControllerElement extends ControllerWidget<IStringController< if (i == -1) i = inputField.length(); } - System.out.println(i); return i; } |