From b890c2f0eec3627e552f1c6cfc846c8a55663243 Mon Sep 17 00:00:00 2001 From: isXander Date: Sun, 11 Dec 2022 18:27:11 +0000 Subject: close #21 --- .../dev/isxander/yacl/gui/CategoryListWidget.java | 5 ++- .../java/dev/isxander/yacl/gui/YACLScreen.java | 5 +-- .../yacl/gui/controllers/ControllerWidget.java | 5 ++- .../string/StringControllerElement.java | 6 ++-- .../java/dev/isxander/yacl/gui/utils/GuiUtils.java | 38 ++++++++++++++++++++++ .../dev/isxander/yacl/gui/utils/RenderUtils.java | 35 -------------------- 6 files changed, 48 insertions(+), 46 deletions(-) create mode 100644 src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/utils/RenderUtils.java (limited to 'src/client/java') diff --git a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java b/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java index 974dc2c..e97f46c 100644 --- a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java @@ -3,11 +3,10 @@ package dev.isxander.yacl.gui; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.systems.RenderSystem; import dev.isxander.yacl.api.ConfigCategory; -import dev.isxander.yacl.gui.utils.RenderUtils; +import dev.isxander.yacl.gui.utils.GuiUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable; -import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.client.util.math.MatrixStack; import java.util.List; @@ -28,7 +27,7 @@ public class CategoryListWidget extends ElementListWidgetExt> extends Abstract hovered = isMouseOver(mouseX, mouseY); Text name = control.option().changed() ? modifiedOptionName : control.option().name(); - Text shortenedName = Text.literal(RenderUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).fillStyle(name.getStyle()); + Text shortenedName = Text.literal(GuiUtils.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(); 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 f536334..ef70341 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 @@ -4,7 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import dev.isxander.yacl.gui.utils.RenderUtils; +import dev.isxander.yacl.gui.utils.GuiUtils; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.InputUtil; @@ -49,12 +49,12 @@ public class StringControllerElement extends ControllerWidget maxWidth) { + string = string.substring(0, Math.max(string.length() - 1 - (firstIter ? 1 : suffix.length() + 1), 0)).trim(); + string += suffix; + + if (string.equals(suffix)) + break; + + firstIter = false; + } + + return string; + } +} diff --git a/src/client/java/dev/isxander/yacl/gui/utils/RenderUtils.java b/src/client/java/dev/isxander/yacl/gui/utils/RenderUtils.java deleted file mode 100644 index 222517b..0000000 --- a/src/client/java/dev/isxander/yacl/gui/utils/RenderUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.isxander.yacl.gui.utils; - -import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.util.TextCollector; -import net.minecraft.client.util.Window; -import net.minecraft.text.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class RenderUtils { - public static void enableScissor(int x, int y, int width, int height) { - Window window = MinecraftClient.getInstance().getWindow(); - double d = window.getScaleFactor(); - RenderSystem.enableScissor((int)(x * d), (int)((window.getScaledHeight() - y - height) * d), (int)(width * d), (int)(height * d)); - } - - public static String shortenString(String string, TextRenderer textRenderer, int maxWidth, String suffix) { - boolean firstIter = true; - while (textRenderer.getWidth(string) > maxWidth) { - string = string.substring(0, Math.max(string.length() - 1 - (firstIter ? 1 : suffix.length() + 1), 0)).trim(); - string += suffix; - - if (string.equals(suffix)) - break; - - firstIter = false; - } - - return string; - } -} -- cgit