Package xyz.gmitch215.socketmc.screen.ui
Class CycleButton<T>
java.lang.Object
xyz.gmitch215.socketmc.screen.ui.AbstractWidget
xyz.gmitch215.socketmc.screen.ui.AbstractTextWidget
xyz.gmitch215.socketmc.screen.ui.AbstractButton
xyz.gmitch215.socketmc.screen.ui.CycleButton<T>
- Type Parameters:
T
- the type of objects to cycle through
- All Implemented Interfaces:
Serializable
,LayoutElement
,Positionable
Represents a Button with multiple states.
Clicking on the button cycles through the states forwards. Holding down Alt while doing this will cycle through the states backwards.
Important: The types specified must be serializable, otherwise it will throw an error.- See Also:
-
Field Summary
Fields inherited from class xyz.gmitch215.socketmc.screen.ui.AbstractButton
BIG_WIDTH, DEFAULT_HEIGHT, DEFAULT_SPACING, DEFAULT_WIDTH, SMALL_WIDTH
Fields inherited from class xyz.gmitch215.socketmc.screen.ui.AbstractWidget
DEFAULT_PADDING, height, tooltip, width, x, y
-
Constructor Summary
ConstructorDescriptionCycleButton
(int x, int y, int width, int height, @NotNull Text message, @NotNull Function<T, Text> stringifier, @NotNull Iterable<T> values) Constructs a new CycleButton.CycleButton
(int x, int y, int width, int height, @NotNull Text message, @NotNull Function<T, Text> stringifier, @NotNull Iterable<T> values, T initialValue) Constructs a new CycleButton.CycleButton
(int x, int y, @NotNull Text message, @NotNull Function<T, Text> stringifier, @NotNull Iterable<T> values) Constructs a new CycleButton using the default dimensions.CycleButton
(int x, int y, @NotNull Text message, @NotNull Function<T, Text> stringifier, @NotNull Iterable<T> values, T initialValue) Constructs a new CycleButton using the default dimensions. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull CycleButton
<Boolean> createBoolean
(int x, int y, int width, int height, @NotNull Text on, @NotNull Text off) Creates a new CycleButton withtrue
andfalse
values.static @NotNull CycleButton
<Boolean> createBoolean
(int x, int y, @NotNull Text on, @NotNull Text off) Creates a new CycleButton withtrue
andfalse
values.static @NotNull CycleButton
<Boolean> createOnOff
(int x, int y) static @NotNull CycleButton
<Boolean> createOnOff
(int x, int y, int width, int height) Gets the initial value, if set.Gets the function to convert the values to text.Gets an immutable copy of the values to cycle through.void
setInitialValue
(T initialValue) Sets the initial value.void
setStringifier
(@NotNull Function<T, Text> stringifier) Sets the function to convert the values to text.Methods inherited from class xyz.gmitch215.socketmc.screen.ui.AbstractTextWidget
equals, getMessageJSON, setMessage, setMessageJSON
Methods inherited from class xyz.gmitch215.socketmc.screen.ui.AbstractWidget
clearListeners, getHeight, getListeners, getTooltip, getWidth, getX, getY, hashCode, onClick, setHeight, setTooltip, setWidth, setX, setY, toString, visitWidgets
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface xyz.gmitch215.socketmc.screen.layout.LayoutElement
setPosition, setSize, setSize, setSize
Methods inherited from interface xyz.gmitch215.socketmc.screen.Positionable
inSamePosition
-
Constructor Details
-
CycleButton
public CycleButton(int x, int y, @NotNull @NotNull Text message, @NotNull @NotNull Function<T, Text> stringifier, @NotNull @NotNull Iterable<T> values) throws IllegalArgumentExceptionConstructs a new CycleButton using the default dimensions.- Parameters:
x
- the x-coordinatey
- the y-coordinatemessage
- the text messagestringifier
- the function to convert the values to textvalues
- the values to cycle through- Throws:
IllegalArgumentException
- if coordinates are negative, or stringifier/values/message is null
-
CycleButton
public CycleButton(int x, int y, int width, int height, @NotNull @NotNull Text message, @NotNull @NotNull Function<T, Text> stringifier, @NotNull @NotNull Iterable<T> values) throws IllegalArgumentExceptionConstructs a new CycleButton.- Parameters:
x
- the x-coordinatey
- the y-coordinatewidth
- the widthheight
- the heightmessage
- the text messagestringifier
- the function to convert the values to textvalues
- the values to cycle through- Throws:
IllegalArgumentException
- if coordinates or dimensions are negative, or stringifier/values/message is null
-
CycleButton
public CycleButton(int x, int y, @NotNull @NotNull Text message, @NotNull @NotNull Function<T, Text> stringifier, @NotNull @NotNull Iterable<T> values, @Nullable T initialValue) throws IllegalArgumentExceptionConstructs a new CycleButton using the default dimensions.- Parameters:
x
- the x-coordinatey
- the y-coordinatemessage
- the text messagestringifier
- the function to convert the values to textvalues
- the values to cycle throughinitialValue
- the initial value, or null if using first value- Throws:
IllegalArgumentException
- if coordinates are negative, or stringifier/values/message is null
-
CycleButton
public CycleButton(int x, int y, int width, int height, @NotNull @NotNull Text message, @NotNull @NotNull Function<T, Text> stringifier, @NotNull @NotNull Iterable<T> values, @Nullable T initialValue) throws IllegalArgumentExceptionConstructs a new CycleButton.- Parameters:
x
- the x-coordinatey
- the y-coordinatewidth
- the widthheight
- the heightmessage
- the text messagestringifier
- the function to convert the values to textvalues
- the values to cycle throughinitialValue
- the initial value, or null if using first value- Throws:
IllegalArgumentException
- if coordinates or dimensions are negative, or stringifier/values/message is null
-
-
Method Details
-
getValues
Gets an immutable copy of the values to cycle through.- Returns:
- the values
-
getInitialValue
Gets the initial value, if set.- Returns:
- the initial value
-
setInitialValue
Sets the initial value.- Parameters:
initialValue
- the initial value, or null if using first value- Throws:
IllegalArgumentException
- if initialValue is not in the values list
-
getStringifier
Gets the function to convert the values to text.- Returns:
- the function to convert the values to text
-
setStringifier
public void setStringifier(@NotNull @NotNull Function<T, Text> stringifier) throws IllegalArgumentExceptionSets the function to convert the values to text.- Parameters:
stringifier
- the function to convert the values to text- Throws:
IllegalArgumentException
- if stringifier is null
-
createOnOff
@NotNull public static @NotNull CycleButton<Boolean> createOnOff(int x, int y) throws IllegalArgumentException - Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- the new CycleButton
- Throws:
IllegalArgumentException
- if constructor fails
-
createBoolean
@NotNull public static @NotNull CycleButton<Boolean> createBoolean(int x, int y, @NotNull @NotNull Text on, @NotNull @NotNull Text off) throws IllegalArgumentException Creates a new CycleButton withtrue
andfalse
values.- Parameters:
x
- the x-coordinatey
- the y-coordinateon
- the text to display when the value istrue
off
- the text to display when the value isfalse
- Returns:
- the new CycleButton
- Throws:
IllegalArgumentException
- if on or off text is null, or constructor fails
-
createOnOff
@NotNull public static @NotNull CycleButton<Boolean> createOnOff(int x, int y, int width, int height) throws IllegalArgumentException - Parameters:
x
- the x-coordinatey
- the y-coordinatewidth
- the widthheight
- the height- Returns:
- the new CycleButton
- Throws:
IllegalArgumentException
- if constructor fails
-
createBoolean
@NotNull public static @NotNull CycleButton<Boolean> createBoolean(int x, int y, int width, int height, @NotNull @NotNull Text on, @NotNull @NotNull Text off) throws IllegalArgumentException Creates a new CycleButton withtrue
andfalse
values.- Parameters:
x
- the x-coordinatey
- the y-coordinatewidth
- the widthheight
- the heighton
- the text to display when the value istrue
off
- the text to display when the value isfalse
- Returns:
- the new CycleButton
- Throws:
IllegalArgumentException
- if on or off text is null, or constructor fails
-