blob: 63b1b42ab46580e82e65dce2c0d676c29614a514 (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package dev.isxander.yacl.gui.controllers;
import dev.isxander.yacl.api.Controller;
import dev.isxander.yacl.api.Option;
import dev.isxander.yacl.api.utils.Dimension;
import dev.isxander.yacl.gui.AbstractWidget;
import dev.isxander.yacl.gui.YACLScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.ApiStatus;
public class LabelController implements Controller<Text> {
private final Option<Text> option;
private final int color;
/**
* Constructs a label controller
*
* @param option bound option
*/
public LabelController(Option<Text> option) {
this(option, -1);
}
/**
* Constructs a label controller
*
* @param option bound option
* @param color color of the label
*/
public LabelController(Option<Text> option, int color) {
this.option = option;
this.color = color;
}
/**
* {@inheritDoc}
*/
@Override
public Option<Text> option() {
return option;
}
public int color() {
return color;
}
@Override
public Text formatValue() {
return option().pendingValue();
}
@Override
public AbstractWidget provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) {
return new LabelControllerElement(widgetDimension);
}
@ApiStatus.Internal
public class LabelControllerElement extends AbstractWidget {
public LabelControllerElement(Dimension<Integer> dim) {
super(dim);
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
textRenderer.drawWithShadow(matrices, formatValue(), dim.x(), dim.centerY() - textRenderer.fontHeight / 2f, color());
}
}
}
|