diff options
-rw-r--r-- | build.gradle.kts | 2 | ||||
-rw-r--r-- | changelogs/2.4.2.md | 2 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java | 11 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/YACLScreen.java | 4 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java | 4 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java | 4 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/impl/OptionImpl.java | 14 | ||||
-rw-r--r-- | src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java | 3 |
8 files changed, 26 insertions, 18 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index b02a9e0..dde9614 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ plugins { val ciRun = System.getenv().containsKey("GITHUB_ACTIONS") group = "dev.isxander" -version = "2.4.1" +version = "2.4.2" if (ciRun) version = "$version+${grgit.branch.current().name.replace('/', '.')}-SNAPSHOT" diff --git a/changelogs/2.4.2.md b/changelogs/2.4.2.md new file mode 100644 index 0000000..eff1299 --- /dev/null +++ b/changelogs/2.4.2.md @@ -0,0 +1,2 @@ +- Prioritised tooltip rendering to above the option rather than below. +- Fix empty tooltips rendering a newline. diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java index ec8e304..46503a6 100644 --- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java +++ b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java @@ -96,17 +96,6 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten return null; } - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - // on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus - boolean clicked = super.mouseReleased(mouseX, mouseY, button); -// if (getFocused() != null) { -// this.getFocused().setFocused(null); -//// this.setFocused(null); -// } - return clicked; - } - /* below code is licensed from cloth-config under LGPL3 modified to inherit vanilla's EntryListWidget and use yarn mappings diff --git a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java index 3b14544..d653d8c 100644 --- a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java @@ -276,8 +276,8 @@ public class YACLScreen extends Screen { int aboveY = yAbove - height + 12; int maxBelow = screenHeight - (belowY + height); int minAbove = aboveY - height; - int y = belowY; - if (maxBelow < -8) + int y = aboveY; + if (minAbove < 8) y = maxBelow > minAbove ? belowY : aboveY; int x = Math.max(centerX - text.getWidth() / 2 - 12, -6); diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java index b3d28b3..2d39eb9 100644 --- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java @@ -7,6 +7,7 @@ import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionGroup; import dev.isxander.yacl.impl.utils.YACLConstants; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; @@ -121,6 +122,9 @@ public final class ConfigCategoryImpl implements ConfigCategory { MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; for (Component line : tooltipLines) { + if (line.getContents() == ComponentContents.EMPTY) + continue; + if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java index 0f883d9..68f53a0 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java @@ -5,6 +5,7 @@ import dev.isxander.yacl.api.ListOption; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionGroup; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; @@ -113,6 +114,9 @@ public final class OptionGroupImpl implements OptionGroup { MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; for (Component line : tooltipLines) { + if (line.getContents() == ComponentContents.EMPTY) + continue; + if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java index 35ad620..644abc9 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java @@ -7,6 +7,7 @@ import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionFlag; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; @@ -195,9 +196,11 @@ public final class OptionImpl<T> implements Option<T> { @Override public Option.Builder<T> tooltip(@NotNull Component... tooltips) { - Validate.notNull(tooltips, "`tooltips` cannot be empty"); + var tooltipFunctions = Arrays.stream(tooltips) + .map(t -> (Function<T, Component>) opt -> t) + .toList(); - this.tooltipGetters.addAll(Stream.of(tooltips).map(Component -> (Function<T, Component>) t -> Component).toList()); + this.tooltipGetters.addAll(tooltipFunctions); return this; } @@ -277,10 +280,15 @@ public final class OptionImpl<T> implements Option<T> { MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; for (Function<T, Component> line : tooltipGetters) { + Component lineComponent = line.apply(value); + + if (lineComponent.getContents() == ComponentContents.EMPTY) + continue; + if (!first) concatenatedTooltip.append("\n"); first = false; - concatenatedTooltip.append(line.apply(value)); + concatenatedTooltip.append(lineComponent); } return concatenatedTooltip; diff --git a/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java b/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java index 1ab4f1d..18d2a3c 100644 --- a/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java +++ b/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java @@ -57,7 +57,6 @@ public class GuiTest { .group(OptionGroup.createBuilder() .name(Component.literal("Boolean Controllers")) .tooltip(Component.literal("Test!")) - .collapsed(true) .option(Option.createBuilder(boolean.class) .name(Component.literal("Boolean Toggle")) .tooltip(value -> Component.literal("A simple toggle button that contains the value '" + value + "'")) @@ -72,6 +71,8 @@ public class GuiTest { .option(Option.createBuilder(boolean.class) .name(Component.literal("Custom Boolean Toggle")) .tooltip(Component.literal("You can customize these controllers like this!")) + .tooltip(Component.empty()) + .tooltip(opt -> Component.empty()) .binding( defaults.customBooleanToggle, () -> config.customBooleanToggle, |