diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-01-19 11:49:51 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-01-19 11:49:51 +0200 |
commit | d028ba6cd2529d18003bcc09a0d7f6be031cbef5 (patch) | |
tree | 028879c7a09eacec9896916d97fd64694996fae0 | |
parent | a24222da0c88df8907b3e2f9187a02293e864dfa (diff) | |
download | LibGui-d028ba6cd2529d18003bcc09a0d7f6be031cbef5.tar.gz LibGui-d028ba6cd2529d18003bcc09a0d7f6be031cbef5.tar.bz2 LibGui-d028ba6cd2529d18003bcc09a0d7f6be031cbef5.zip |
Add select-all to text fields, fix selections spilling outside the widget
Closes #28 and fixes #29.
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index 12c6ae6..97023aa 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java @@ -390,7 +390,7 @@ public class WTextField extends WWidget { b = a; a = tmp; } - invertedRect(textX+a-1, textY-1, b-a, 12); + invertedRect(textX+a-1, textY-1, Math.min(b-a, width - OFFSET_X_TEXT), 12); // int int_10 = int_6 + MinecraftClient.getInstance().textRenderer.getStringWidth(trimText.substring(0, adjustedCursor)); // var10002 = int_7 - 1; // var10003 = int_10 - 1; @@ -557,7 +557,7 @@ public class WTextField extends WWidget { @Override public void onKeyPressed(int ch, int key, int modifiers) { if (!this.editable) return; - + if (Screen.isCopy(ch)) { String selection = getSelection(); if (selection!=null) { @@ -594,6 +594,10 @@ public class WTextField extends WWidget { } } return; + } else if (Screen.isSelectAll(ch)) { + select = 0; + cursor = text.length(); + return; } //System.out.println("Ch: "+ch+", Key: "+key+", Mod: "+modifiers); |