diff options
author | isXander <xandersmith2008@gmail.com> | 2022-12-10 23:14:25 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2022-12-10 23:14:25 +0000 |
commit | 0b667b3beb5169888b9fbbb1464c4d88f866c7cb (patch) | |
tree | ac667a066c6be37ced57245be0abf90c24969a7b /src/client/java/dev/isxander/yacl/gui | |
parent | 2919ef30b8be41b7089c759840c1021f6d03f219 (diff) | |
download | YetAnotherConfigLib-0b667b3beb5169888b9fbbb1464c4d88f866c7cb.tar.gz YetAnotherConfigLib-0b667b3beb5169888b9fbbb1464c4d88f866c7cb.tar.bz2 YetAnotherConfigLib-0b667b3beb5169888b9fbbb1464c4d88f866c7cb.zip |
allow pasting in color controllers
Diffstat (limited to 'src/client/java/dev/isxander/yacl/gui')
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java | 17 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java | 58 |
2 files changed, 53 insertions, 22 deletions
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 b8e1942..7ed9ec1 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java @@ -126,6 +126,7 @@ public class ColorController implements IStringController<Color> { @Override public void write(String string) { + if (string.startsWith("0x")) string = string.substring(2); for (char chr : string.toCharArray()) { if (!allowedChars.contains(Character.toLowerCase(chr))) { return; @@ -156,11 +157,25 @@ public class ColorController implements IStringController<Color> { @Override protected void doDelete() { + if (caretPos >= 1) { + if (modifyInput(builder -> builder.setCharAt(caretPos, '0'))) { + updateControl(); + } + } + } + + @Override + protected boolean doCut() { + return false; + } + @Override + protected boolean doCopy() { + return false; } @Override - protected boolean canUseShortcuts() { + protected boolean doSelectAll() { 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 d2c752b..68d02c6 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 @@ -193,28 +193,48 @@ 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(); - checkRenderOffset(); - selectionLength = -caretPos; - return true; - } + if (Screen.isPaste(keyCode)) { + return doPaste(); + } else if (Screen.isCopy(keyCode)) { + return doCopy(); + } else if (Screen.isCut(keyCode)) { + return doCut(); + } else if (Screen.isSelectAll(keyCode)) { + return doSelectAll(); } return false; } + protected boolean doPaste() { + this.write(client.keyboard.getClipboard()); + return true; + } + + protected boolean doCopy() { + if (selectionLength != 0) { + client.keyboard.setClipboard(getSelection()); + return true; + } + return false; + } + + protected boolean doCut() { + if (selectionLength != 0) { + client.keyboard.setClipboard(getSelection()); + this.write(""); + return true; + } + return false; + } + + protected boolean doSelectAll() { + caretPos = inputField.length(); + checkRenderOffset(); + selectionLength = -caretPos; + return true; + } + protected void checkRenderOffset() { if (textRenderer.getWidth(inputField) < getUnshiftedLength()) { renderOffset = 0; @@ -241,10 +261,6 @@ public class StringControllerElement extends ControllerWidget<IStringController< return true; } - protected boolean canUseShortcuts() { - return true; - } - protected void doBackspace() { if (selectionLength != 0) { write(""); |