1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package dev.isxander.yacl.gui;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
public class TooltipButtonWidget extends Button {
protected final Screen screen;
protected MultiLineLabel wrappedDescription = null;
public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Component message, Component tooltip, OnPress onPress) {
super(x, y, width, height, message, onPress, DEFAULT_NARRATION);
this.screen = screen;
if (tooltip != null)
setTooltip(tooltip);
}
public void renderHoveredTooltip(GuiGraphics graphics) {
if (isHoveredOrFocused() && wrappedDescription != null) {
YACLScreen.renderMultilineTooltip(graphics, Minecraft.getInstance().font, wrappedDescription, getX() + width / 2, getY() - 4, getY() + height + 4, screen.width, screen.height);
}
}
public void setTooltip(Component tooltip) {
wrappedDescription = MultiLineLabel.create(Minecraft.getInstance().font, tooltip, screen.width / 3 - 5);
}
}
|