diff options
author | isXander <xandersmith2008@gmail.com> | 2022-12-11 12:54:53 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2022-12-11 12:54:53 +0000 |
commit | 063e784f1a142ecbc34afdb837bcacee9cb06286 (patch) | |
tree | f6141ec49814108a57d1124d0c30bc02b902cbf6 /src/client/java/dev/isxander/yacl/gui/controllers | |
parent | 0b667b3beb5169888b9fbbb1464c4d88f866c7cb (diff) | |
download | YetAnotherConfigLib-063e784f1a142ecbc34afdb837bcacee9cb06286.tar.gz YetAnotherConfigLib-063e784f1a142ecbc34afdb837bcacee9cb06286.tar.bz2 YetAnotherConfigLib-063e784f1a142ecbc34afdb837bcacee9cb06286.zip |
Use pixel based approach for text overflow to fix string clipping depending on char width
Diffstat (limited to 'src/client/java/dev/isxander/yacl/gui/controllers')
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java | 21 |
1 files changed, 11 insertions, 10 deletions
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 68d02c6..f536334 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 @@ -51,10 +51,8 @@ public class StringControllerElement extends ControllerWidget<IStringController< Text valueText = getValueText(); if (!isHovered()) valueText = Text.literal(RenderUtils.shortenString(valueText.getString(), textRenderer, getDimension().width() / 2, "...")).setStyle(valueText.getStyle()); - int overflowWidth = textRenderer.getWidth(inputField.substring(inputField.length() - renderOffset)); - matrices.push(); - int textX = getDimension().xLimit() - textRenderer.getWidth(valueText) + overflowWidth - getXPadding(); + int textX = getDimension().xLimit() - textRenderer.getWidth(valueText) + renderOffset - getXPadding(); matrices.translate(textX, getTextY(), 0); RenderUtils.enableScissor(inputFieldBounds.x(), inputFieldBounds.y(), inputFieldBounds.width() + 1, inputFieldBounds.height() + 2); textRenderer.drawWithShadow(matrices, valueText, 0, 0, getValueColor()); @@ -241,14 +239,17 @@ public class StringControllerElement extends ControllerWidget<IStringController< return; } - String inp = inputField.substring(0, inputField.length() - renderOffset); - int obstructionWidth = textRenderer.getWidth(inp) - getUnshiftedLength(); - int length = inp.length() - textRenderer.trimToWidth(inp, obstructionWidth).length(); + int textX = getDimension().xLimit() - textRenderer.getWidth(inputField) - getXPadding(); + int caretX = textX + textRenderer.getWidth(inputField.substring(0, caretPos)) - 1; + + int minX = getDimension().xLimit() - getXPadding() - getUnshiftedLength(); + int maxX = minX + getUnshiftedLength(); - if (caretPos < inputField.length() - renderOffset - length) - renderOffset = inputField.length() - caretPos - length; - if (caretPos > inputField.length() - renderOffset) - renderOffset = inputField.length() - caretPos; + if (caretX + renderOffset < minX) { + renderOffset = minX - caretX; + } else if (caretX + renderOffset > maxX) { + renderOffset = maxX - caretX; + } } @Override |