Skip to content

Commit 25f8d0b

Browse files
committed
prioritise tooltip rendering above & filter empty tooltips
1 parent 74bcc11 commit 25f8d0b

8 files changed

Lines changed: 26 additions & 18 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
val ciRun = System.getenv().containsKey("GITHUB_ACTIONS")
1717

1818
group = "dev.isxander"
19-
version = "2.4.1"
19+
version = "2.4.2"
2020

2121
if (ciRun)
2222
version = "$version+${grgit.branch.current().name.replace('/', '.')}-SNAPSHOT"

changelogs/2.4.2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Prioritised tooltip rendering to above the option rather than below.
2+
- Fix empty tooltips rendering a newline.

src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ protected E getEntryAtPosition(double x, double y) {
9696
return null;
9797
}
9898

99-
@Override
100-
public boolean mouseReleased(double mouseX, double mouseY, int button) {
101-
// on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus
102-
boolean clicked = super.mouseReleased(mouseX, mouseY, button);
103-
// if (getFocused() != null) {
104-
// this.getFocused().setFocused(null);
105-
//// this.setFocused(null);
106-
// }
107-
return clicked;
108-
}
109-
11099
/*
111100
below code is licensed from cloth-config under LGPL3
112101
modified to inherit vanilla's EntryListWidget and use yarn mappings

src/client/java/dev/isxander/yacl/gui/YACLScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ public static void renderMultilineTooltip(PoseStack matrices, Font font, MultiLi
276276
int aboveY = yAbove - height + 12;
277277
int maxBelow = screenHeight - (belowY + height);
278278
int minAbove = aboveY - height;
279-
int y = belowY;
280-
if (maxBelow < -8)
279+
int y = aboveY;
280+
if (minAbove < 8)
281281
y = maxBelow > minAbove ? belowY : aboveY;
282282

283283
int x = Math.max(centerX - text.getWidth() / 2 - 12, -6);

src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import dev.isxander.yacl.api.OptionGroup;
88
import dev.isxander.yacl.impl.utils.YACLConstants;
99
import net.minecraft.network.chat.Component;
10+
import net.minecraft.network.chat.ComponentContents;
1011
import net.minecraft.network.chat.MutableComponent;
1112
import org.apache.commons.lang3.Validate;
1213
import org.jetbrains.annotations.ApiStatus;
@@ -121,6 +122,9 @@ public ConfigCategory build() {
121122
MutableComponent concatenatedTooltip = Component.empty();
122123
boolean first = true;
123124
for (Component line : tooltipLines) {
125+
if (line.getContents() == ComponentContents.EMPTY)
126+
continue;
127+
124128
if (!first) concatenatedTooltip.append("\n");
125129
first = false;
126130

src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dev.isxander.yacl.api.Option;
66
import dev.isxander.yacl.api.OptionGroup;
77
import net.minecraft.network.chat.Component;
8+
import net.minecraft.network.chat.ComponentContents;
89
import net.minecraft.network.chat.MutableComponent;
910
import org.apache.commons.lang3.Validate;
1011
import org.jetbrains.annotations.ApiStatus;
@@ -113,6 +114,9 @@ public OptionGroup build() {
113114
MutableComponent concatenatedTooltip = Component.empty();
114115
boolean first = true;
115116
for (Component line : tooltipLines) {
117+
if (line.getContents() == ComponentContents.EMPTY)
118+
continue;
119+
116120
if (!first) concatenatedTooltip.append("\n");
117121
first = false;
118122

src/client/java/dev/isxander/yacl/impl/OptionImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import dev.isxander.yacl.api.OptionFlag;
88
import net.minecraft.ChatFormatting;
99
import net.minecraft.network.chat.Component;
10+
import net.minecraft.network.chat.ComponentContents;
1011
import net.minecraft.network.chat.MutableComponent;
1112
import org.apache.commons.lang3.Validate;
1213
import org.jetbrains.annotations.ApiStatus;
@@ -195,9 +196,11 @@ public final Option.Builder<T> tooltip(@NotNull Function<T, Component>... toolti
195196

196197
@Override
197198
public Option.Builder<T> tooltip(@NotNull Component... tooltips) {
198-
Validate.notNull(tooltips, "`tooltips` cannot be empty");
199+
var tooltipFunctions = Arrays.stream(tooltips)
200+
.map(t -> (Function<T, Component>) opt -> t)
201+
.toList();
199202

200-
this.tooltipGetters.addAll(Stream.of(tooltips).map(Component -> (Function<T, Component>) t -> Component).toList());
203+
this.tooltipGetters.addAll(tooltipFunctions);
201204
return this;
202205
}
203206

@@ -277,10 +280,15 @@ public Option<T> build() {
277280
MutableComponent concatenatedTooltip = Component.empty();
278281
boolean first = true;
279282
for (Function<T, Component> line : tooltipGetters) {
283+
Component lineComponent = line.apply(value);
284+
285+
if (lineComponent.getContents() == ComponentContents.EMPTY)
286+
continue;
287+
280288
if (!first) concatenatedTooltip.append("\n");
281289
first = false;
282290

283-
concatenatedTooltip.append(line.apply(value));
291+
concatenatedTooltip.append(lineComponent);
284292
}
285293

286294
return concatenatedTooltip;

src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ private static Screen getFullTestSuite(Screen parent) {
5757
.group(OptionGroup.createBuilder()
5858
.name(Component.literal("Boolean Controllers"))
5959
.tooltip(Component.literal("Test!"))
60-
.collapsed(true)
6160
.option(Option.createBuilder(boolean.class)
6261
.name(Component.literal("Boolean Toggle"))
6362
.tooltip(value -> Component.literal("A simple toggle button that contains the value '" + value + "'"))
@@ -72,6 +71,8 @@ private static Screen getFullTestSuite(Screen parent) {
7271
.option(Option.createBuilder(boolean.class)
7372
.name(Component.literal("Custom Boolean Toggle"))
7473
.tooltip(Component.literal("You can customize these controllers like this!"))
74+
.tooltip(Component.empty())
75+
.tooltip(opt -> Component.empty())
7576
.binding(
7677
defaults.customBooleanToggle,
7778
() -> config.customBooleanToggle,

0 commit comments

Comments
 (0)