Skip to content

Commit d712280

Browse files
committed
Fixed an issue with tooltip wrapping.
1 parent 512050d commit d712280

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Diff for: src/main/java/codechicken/lib/gui/modular/lib/GuiRender.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -1302,11 +1302,8 @@ public void renderTooltip(Component message, double mouseX, double mouseY) {
13021302
}
13031303

13041304
public void renderTooltip(Component message, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
1305-
this.renderTooltip(List.of(message.getVisualOrderText()), mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom);
1306-
}
1307-
1308-
public void componentTooltip(List<Component> tooltips, double mouseX, double mouseY) {
1309-
componentTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f);
1305+
List<ClientTooltipComponent> list = ForgeHooksClient.gatherTooltipComponents(tooltipStack, List.of(message), Optional.empty(), (int) mouseX, guiWidth(), guiHeight(), font());
1306+
this.renderTooltipInternal(list, mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, DefaultTooltipPositioner.INSTANCE);
13101307
}
13111308

13121309
public void componentTooltip(List<Component> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
@@ -1318,21 +1315,34 @@ public void componentTooltip(List<? extends FormattedText> tooltips, double mous
13181315
componentTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f, stack);
13191316
}
13201317

1321-
public void componentTooltip(List<? extends net.minecraft.network.chat.FormattedText> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom, ItemStack stack) {
1318+
public void componentTooltip(List<? extends FormattedText> tooltips, double mouseX, double mouseY) {
1319+
componentTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f, ItemStack.EMPTY);
1320+
}
1321+
1322+
public void componentTooltip(List<? extends FormattedText> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom, ItemStack stack) {
13221323
this.tooltipStack = stack;
13231324
List<ClientTooltipComponent> list = ForgeHooksClient.gatherTooltipComponents(tooltipStack, tooltips, Optional.empty(), (int) mouseX, guiWidth(), guiHeight(), font());
13241325
this.renderTooltipInternal(list, mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, DefaultTooltipPositioner.INSTANCE);
13251326
this.tooltipStack = ItemStack.EMPTY;
13261327
}
13271328

1329+
/**
1330+
* Warning: This tooltip method with not automatically wrap tooltip lines
1331+
*/
13281332
public void renderTooltip(List<? extends FormattedCharSequence> tooltips, double mouseX, double mouseY) {
13291333
renderTooltip(tooltips, mouseX, mouseY, 0xf0100010, 0xf0100010, 0x505000ff, 0x5028007f);
13301334
}
13311335

1336+
/**
1337+
* Warning: This tooltip method with not automatically wrap tooltip lines
1338+
*/
13321339
public void renderTooltip(List<? extends FormattedCharSequence> tooltips, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
13331340
this.renderTooltipInternal(tooltips.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, DefaultTooltipPositioner.INSTANCE);
13341341
}
13351342

1343+
/**
1344+
* Warning: This tooltip method with not automatically wrap tooltip lines
1345+
*/
13361346
public void renderTooltip(List<FormattedCharSequence> tooltips, ClientTooltipPositioner positioner, double mouseX, double mouseY, int backgroundTop, int backgroundBottom, int borderTop, int borderBottom) {
13371347
this.renderTooltipInternal(tooltips.stream().map(ClientTooltipComponent::create).collect(Collectors.toList()), mouseX, mouseY, backgroundTop, backgroundBottom, borderTop, borderBottom, positioner);
13381348
}

Diff for: src/main/java/codechicken/lib/gui/modular/lib/TooltipHandler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.Collections;
99
import java.util.List;
10+
import java.util.Optional;
1011
import java.util.function.Supplier;
1112

1213
/**
@@ -100,7 +101,7 @@ default boolean renderTooltip(GuiRender render, double mouseX, double mouseY) {
100101
List<Component> list = supplier.get();
101102
if (list.isEmpty()) return false;
102103
//Run all components though split to account for newline characters in translations
103-
render.renderTooltip(list.stream().flatMap(component -> render.font().split(component, Integer.MAX_VALUE).stream()).toList(), mouseX, mouseY);
104+
render.componentTooltip(list.stream().flatMap(component -> render.font().getSplitter().splitLines(component, Integer.MAX_VALUE, component.getStyle()).stream()).toList(), mouseX, mouseY);
104105
return true;
105106
}
106107
}

0 commit comments

Comments
 (0)