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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.shedaniel.rei.api.widgets;
import me.shedaniel.math.Point;
import me.shedaniel.rei.api.REIHelper;
import me.shedaniel.rei.gui.widget.WidgetWithBounds;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
public abstract class Label extends WidgetWithBounds {
public static final int LEFT_ALIGNED = -1;
public static final int CENTER = 0;
public static final int RIGHT_ALIGNED = 1;
/**
* @return whether the label is clickable, ignores if onClick is set.
*/
public abstract boolean isClickable();
/**
* Sets whether the label is clickable, ignores if onClick is set.
*
* @param clickable whether the label is clickable.
*/
public abstract void setClickable(boolean clickable);
/**
* Sets the label as clickable, ignores if onClick is set.
*
* @return the label itself.
*/
@NotNull
public final Label clickable() {
return clickable(true);
}
/**
* Sets whether the label is clickable, ignores if onClick is set.
*
* @param clickable whether the label is clickable.
* @return the label itself.
*/
@NotNull
public final Label clickable(boolean clickable) {
setClickable(clickable);
return this;
}
/**
* @return the consumer on click, only applicable if the label is clickable, null if not set.
*/
@Nullable
public abstract Consumer<Label> getOnClick();
/**
* Sets the on click consumer, only applicable if the label is clickable.
*
* @param onClick the on click consumer, only applicable if the label is clickable.
*/
public abstract void setOnClick(@Nullable Consumer<Label> onClick);
/**
* Sets the on click consumer, only applicable if the label is clickable.
*
* @param onClick the on click consumer, only applicable if the label is clickable.
* @return the label itself.
*/
@NotNull
public final Label onClick(@Nullable Consumer<Label> onClick) {
setOnClick(onClick);
return this;
}
/**
* @return the consumer before render, null if not set.
*/
@Nullable
public abstract BiConsumer<MatrixStack, Label> getOnRender();
/**
* Sets the consumer before render.
*
* @param onRender the consumer before render.
*/
public abstract void setOnRender(@Nullable BiConsumer<MatrixStack, Label> onRender);
/**
* Sets the consumer before render.
*
* @param onRender the consumer before render.
* @return the label itself.
*/
@NotNull
public final Label onRender(@Nullable BiConsumer<MatrixStack, Label> onRender) {
setOnRender(onRender);
return this;
}
/**
* @return whether the label is focusable by pressing tab, ignored if not clickable.
*/
public abstract boolean isFocusable();
/**
* Sets whether the label is focusable by pressing tab, ignored if not clickable.
*
* @param focusable whether the label is focusable by pressing tab, ignored if not clickable.
*/
public abstract void setFocusable(boolean focusable);
/**
* Sets whether the label is focusable by pressing tab, ignored if not clickable.
*
* @param focusable whether the label is focusable by pressing tab, ignored if not clickable.
* @return the label itself.
*/
@NotNull
public final Label focusable(boolean focusable) {
setFocusable(focusable);
return this;
}
/**
* @return the tooltip from the current tooltip function, null if no tooltip.
*/
@Nullable
public abstract String getTooltip();
/**
* Sets the tooltip function used to get the tooltip.
*
* @param tooltip the tooltip function used to get the tooltip.
*/
public abstract void setTooltip(@Nullable Function<Label, @Nullable String> tooltip);
/**
* Sets the tooltip.
*
* @param tooltip the lines of tooltip.
* @return the label itself.
*/
@NotNull
public final Label tooltipLines(@NotNull String... tooltip) {
return tooltipLine(String.join("\n", tooltip));
}
/**
* Sets the tooltip.
*
* @param tooltip the line of tooltip.
* @return the label itself.
*/
@NotNull
public final Label tooltipLine(@Nullable String tooltip) {
return tooltipSupplier(label -> tooltip);
}
/**
* Sets the tooltip function.
*
* @param tooltip the tooltip function used to get the tooltip.
* @return the label itself.
*/
@NotNull
public final Label tooltipSupplier(@Nullable Function<Label, @Nullable String> tooltip) {
setTooltip(tooltip);
return this;
}
/**
* Gets the horizontal alignment of the label, defaulted as centered.
*
* @return {@link Label#LEFT_ALIGNED} if left aligned, {@link Label#CENTER} if centered or {@link Label#RIGHT_ALIGNED} if right aligned}.
*/
public abstract int getHorizontalAlignment();
@NotNull
public final Label centered() {
return horizontalAlignment(CENTER);
}
@NotNull
public final Label leftAligned() {
return horizontalAlignment(LEFT_ALIGNED);
}
@NotNull
public final Label rightAligned() {
return horizontalAlignment(RIGHT_ALIGNED);
}
public abstract void setHorizontalAlignment(int horizontalAlignment);
public final Label horizontalAlignment(int horizontalAlignment) {
setHorizontalAlignment(horizontalAlignment);
return this;
}
public abstract boolean hasShadow();
@NotNull
public final Label noShadow() {
return shadow(false);
}
@NotNull
public final Label shadow() {
return shadow(true);
}
public abstract void setShadow(boolean hasShadow);
@NotNull
public final Label shadow(boolean hasShadow) {
setShadow(hasShadow);
return this;
}
public abstract int getColor();
public abstract void setColor(int color);
@NotNull
public final Label color(int lightModeColor, int darkModeColor) {
return color(REIHelper.getInstance().isDarkThemeEnabled() ? darkModeColor : lightModeColor);
}
@NotNull
public final Label color(int color) {
setColor(color);
return this;
}
public abstract int getHoveredColor();
public abstract void setHoveredColor(int hoveredColor);
@NotNull
public final Label hoveredColor(int lightModeColor, int darkModeColor) {
return hoveredColor(REIHelper.getInstance().isDarkThemeEnabled() ? darkModeColor : lightModeColor);
}
@NotNull
public final Label hoveredColor(int color) {
setHoveredColor(color);
return this;
}
@NotNull
public abstract Point getPoint();
public final int getX() {
return getPoint().getX();
}
public final int getY() {
return getPoint().getY();
}
public abstract void setPoint(@NotNull Point point);
@NotNull
public final Label point(@NotNull Point point) {
setPoint(point);
return this;
}
@NotNull
public abstract Text getText();
public abstract void setText(@NotNull Text text);
@NotNull
public final Label text(@NotNull Text text) {
setText(text);
return this;
}
}
|