diff options
author | isXander <xandersmith2008@gmail.com> | 2022-12-09 20:53:19 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2022-12-09 20:53:19 +0000 |
commit | 3e03edff9633de35068cbb0e11c111a70585a74d (patch) | |
tree | 0c2cb9f71121ba0e989681d669406f9de222ba9d /src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java | |
parent | 62b1450df690c4b22c0eb42f02a6b0c507111686 (diff) | |
download | YetAnotherConfigLib-3e03edff9633de35068cbb0e11c111a70585a74d.tar.gz YetAnotherConfigLib-3e03edff9633de35068cbb0e11c111a70585a74d.tar.bz2 YetAnotherConfigLib-3e03edff9633de35068cbb0e11c111a70585a74d.zip |
unlimited string length in controller
Diffstat (limited to 'src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java')
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index cebaba7..9a16d22 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -4,6 +4,7 @@ import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; +import dev.isxander.yacl.gui.utils.RenderUtils; import dev.isxander.yacl.impl.utils.YACLConstants; import net.minecraft.client.font.MultilineText; import net.minecraft.client.gui.DrawableHelper; @@ -38,20 +39,7 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract hovered = isMouseOver(mouseX, mouseY); Text name = control.option().changed() ? modifiedOptionName : control.option().name(); - String nameString = name.getString(); - - boolean firstIter = true; - while (textRenderer.getWidth(nameString) > getDimension().width() - getControlWidth() - getXPadding() - 7) { - nameString = nameString.substring(0, Math.max(nameString.length() - (firstIter ? 2 : 5), 0)).trim(); - nameString += "..."; - - if (nameString.equals("...")) - break; - - firstIter = false; - } - - Text shortenedName = Text.literal(nameString).fillStyle(name.getStyle()); + Text shortenedName = Text.literal(RenderUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).fillStyle(name.getStyle()); drawButtonRect(matrices, getDimension().x(), getDimension().y(), getDimension().xLimit(), getDimension().yLimit(), isHovered(), isAvailable()); matrices.push(); @@ -67,7 +55,7 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract @Override public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { - if (hovered) { + if (hovered || focused) { YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); } } |