Skip to content

Commit 58a1948

Browse files
committed
convenience methods for AbstractCycleButtonWidget
1 parent f132b6e commit 58a1948

File tree

3 files changed

+224
-0
lines changed

3 files changed

+224
-0
lines changed

src/main/java/com/cleanroommc/modularui/widgets/AbstractCycleButtonWidget.java

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import com.cleanroommc.modularui.api.ITheme;
44
import com.cleanroommc.modularui.api.drawable.IDrawable;
55
import com.cleanroommc.modularui.api.drawable.IKey;
6+
import com.cleanroommc.modularui.api.drawable.ITextLine;
67
import com.cleanroommc.modularui.api.value.IBoolValue;
78
import com.cleanroommc.modularui.api.value.IEnumValue;
89
import com.cleanroommc.modularui.api.value.IIntValue;
910
import com.cleanroommc.modularui.api.widget.Interactable;
1011
import com.cleanroommc.modularui.drawable.UITexture;
1112
import com.cleanroommc.modularui.screen.RichTooltip;
1213
import com.cleanroommc.modularui.theme.WidgetTheme;
14+
import com.cleanroommc.modularui.utils.Alignment;
1315
import com.cleanroommc.modularui.value.IntValue;
1416
import com.cleanroommc.modularui.value.sync.SyncHandler;
1517
import com.cleanroommc.modularui.widget.Widget;
@@ -219,6 +221,217 @@ protected W addTooltip(int state, String tooltip) {
219221
return addTooltip(state, IKey.str(tooltip));
220222
}
221223

224+
/**
225+
* Adds a tooltip element to all states.
226+
*
227+
* @param s element
228+
* @return this
229+
*/
230+
@Override
231+
public W addTooltipElement(String s) {
232+
for (RichTooltip tooltip : this.stateTooltip) {
233+
tooltip.add(s);
234+
}
235+
return getThis();
236+
}
237+
238+
/**
239+
* Adds tooltip drawables as lines to all states.
240+
*
241+
* @param lines drawables
242+
* @return this
243+
*/
244+
@Override
245+
public W addTooltipDrawableLines(Iterable<IDrawable> lines) {
246+
for (RichTooltip tooltip : this.stateTooltip) {
247+
tooltip.addDrawableLines(lines);
248+
}
249+
return getThis();
250+
}
251+
252+
/**
253+
* Adds a tooltip element to all states.
254+
*
255+
* @param drawable element
256+
* @return this
257+
*/
258+
@Override
259+
public W addTooltipElement(IDrawable drawable) {
260+
for (RichTooltip tooltip : this.stateTooltip) {
261+
tooltip.add(drawable);
262+
}
263+
return getThis();
264+
}
265+
266+
/**
267+
* Adds a tooltip line to all states.
268+
*
269+
* @param line tooltip line
270+
* @return this
271+
*/
272+
@Override
273+
public W addTooltipLine(ITextLine line) {
274+
for (RichTooltip tooltip : this.stateTooltip) {
275+
tooltip.addLine(line);
276+
}
277+
return getThis();
278+
}
279+
280+
/**
281+
* Adds a tooltip line to all states.
282+
*
283+
* @param drawable tooltip line
284+
* @return this
285+
*/
286+
@Override
287+
public W addTooltipLine(IDrawable drawable) {
288+
for (RichTooltip tooltip : this.stateTooltip) {
289+
tooltip.addLine(drawable);
290+
}
291+
return getThis();
292+
}
293+
294+
/**
295+
* Adds tooltip lines to all states.
296+
*
297+
* @param lines tooltip lines
298+
* @return this
299+
*/
300+
@Override
301+
public W addTooltipStringLines(Iterable<String> lines) {
302+
for (RichTooltip tooltip : this.stateTooltip) {
303+
tooltip.addStringLines(lines);
304+
}
305+
return getThis();
306+
}
307+
308+
/**
309+
* Applies a function to the tooltip of all states once.
310+
*
311+
* @param tooltipConsumer tooltip function
312+
* @return this
313+
*/
314+
@Override
315+
public W tooltipStatic(Consumer<RichTooltip> tooltipConsumer) {
316+
for (RichTooltip tooltip : this.stateTooltip) {
317+
tooltipConsumer.accept(tooltip);
318+
}
319+
return getThis();
320+
}
321+
322+
/**
323+
* Applies a function to the tooltip of all states every time the tooltip needs to update.
324+
*
325+
* @param tooltipBuilder tooltip function
326+
* @return this
327+
*/
328+
@Override
329+
public W tooltipDynamic(Consumer<RichTooltip> tooltipBuilder) {
330+
for (RichTooltip tooltip : this.stateTooltip) {
331+
tooltip.tooltipBuilder(tooltipBuilder);
332+
}
333+
return getThis();
334+
}
335+
336+
/**
337+
* Sets the tooltip alignment of all states.
338+
*
339+
* @param alignment alignment
340+
* @return this
341+
*/
342+
@Override
343+
public W tooltipAlignment(Alignment alignment) {
344+
for (RichTooltip tooltip : this.stateTooltip) {
345+
tooltip.alignment(alignment);
346+
}
347+
return getThis();
348+
}
349+
350+
/**
351+
* Sets the tooltip position of all states.
352+
*
353+
* @param pos tooltip pos
354+
* @return this
355+
*/
356+
@Override
357+
public W tooltipPos(RichTooltip.Pos pos) {
358+
for (RichTooltip tooltip : this.stateTooltip) {
359+
tooltip.pos(pos);
360+
}
361+
return getThis();
362+
}
363+
364+
/**
365+
* Sets the tooltip position of all states.
366+
*
367+
* @param x x
368+
* @param y y
369+
* @return this
370+
*/
371+
@Override
372+
public W tooltipPos(int x, int y) {
373+
for (RichTooltip tooltip : this.stateTooltip) {
374+
tooltip.pos(x, y);
375+
}
376+
return getThis();
377+
}
378+
379+
/**
380+
* Sets the tooltip scale of all states.
381+
*
382+
* @param scale tooltip scale
383+
* @return this
384+
*/
385+
@Override
386+
public W tooltipScale(float scale) {
387+
for (RichTooltip tooltip : this.stateTooltip) {
388+
tooltip.scale(scale);
389+
}
390+
return getThis();
391+
}
392+
393+
/**
394+
* Sets the tooltip text color of all states.
395+
*
396+
* @param textColor tooltip text color
397+
* @return this
398+
*/
399+
@Override
400+
public W tooltipTextColor(int textColor) {
401+
for (RichTooltip tooltip : this.stateTooltip) {
402+
tooltip.textColor(textColor);
403+
}
404+
return getThis();
405+
}
406+
407+
/**
408+
* Sets the tooltip text shadow of all states.
409+
*
410+
* @param textShadow tooltip pos
411+
* @return this
412+
*/
413+
@Override
414+
public W tooltipTextShadow(boolean textShadow) {
415+
for (RichTooltip tooltip : this.stateTooltip) {
416+
tooltip.textShadow(textShadow);
417+
}
418+
return getThis();
419+
}
420+
421+
/**
422+
* Sets the tooltip show up timer of all states.
423+
*
424+
* @param showUpTimer tooltip show up timer
425+
* @return this
426+
*/
427+
@Override
428+
public W tooltipShowUpTimer(int showUpTimer) {
429+
for (RichTooltip tooltip : this.stateTooltip) {
430+
tooltip.showUpTimer(showUpTimer);
431+
}
432+
return getThis();
433+
}
434+
222435
protected W stateCount(int stateCount) {
223436
this.stateCount = stateCount;
224437
// adjust tooltip buffer size

src/main/java/com/cleanroommc/modularui/widgets/CycleButtonWidget.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
import java.util.function.Consumer;
88

9+
/**
10+
* A button which cycles between multiple states by clicking on it. Background, overlay and tooltip can be supplied per state.
11+
* <p>Note that you need to set the amount of states before setting any state backgrounds etc. The state count is automatically set, if the
12+
* passed {@link IIntValue} is a {@link com.cleanroommc.modularui.api.value.IEnumValue IEnumValue} or a
13+
* {@link com.cleanroommc.modularui.api.value.IBoolValue IBoolValue}.</p>
14+
* @see ToggleButton
15+
*/
916
public class CycleButtonWidget extends AbstractCycleButtonWidget<CycleButtonWidget> {
1017

1118
@Override

src/main/java/com/cleanroommc/modularui/widgets/ToggleButton.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
import java.util.function.Consumer;
1111

12+
/**
13+
* A button which cycles between 2 states by clicking on it. Background, overlay and tooltip can be supplied per state.
14+
* @see CycleButtonWidget
15+
*/
1216
public class ToggleButton extends AbstractCycleButtonWidget<ToggleButton> {
1317

1418
private boolean invert = false;

0 commit comments

Comments
 (0)