Class WToggleButton
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WToggleButton
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a toggle button with default images and no label.WToggleButton(Texture onImage, Texture offImage) Constructs a toggle button with custom images and no label.WToggleButton(Texture onImage, Texture offImage, net.minecraft.network.chat.Component label) Constructs a toggle button with custom images.WToggleButton(net.minecraft.network.chat.Component label) Constructs a toggle button with default images.WToggleButton(net.minecraft.resources.Identifier onImage, net.minecraft.resources.Identifier offImage) Constructs a toggle button with custom images and no label.WToggleButton(net.minecraft.resources.Identifier onImage, net.minecraft.resources.Identifier offImage, net.minecraft.network.chat.Component label) Constructs a toggle button with custom images. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(net.minecraft.client.gui.narration.NarrationElementOutput builder) Adds the narrations of this widget to a narration builder.booleancanFocus()Tests whether this widget can have the focus in the GUI.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).@Nullable net.minecraft.network.chat.ComponentgetLabel()booleanonClick(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) Notifies this widget that the mouse has been pressed and released, both while inside its bounds.onKeyPressed(net.minecraft.client.input.KeyEvent input) Notifies this widget that a key has been pressed.protected voidonToggle(boolean on) voidpaint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Paints this widget.setColor(int light, int dark) setFocusImage(Texture focusImage) setOffImage(Texture offImage) setOnImage(Texture onImage) setOnToggle(@Nullable Consumer<Boolean> onToggle) voidsetToggle(boolean on) Methods inherited from class WWidget
addPainters, addTooltip, canFocusForTextInput, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onFocusGained, onFocusLost, onHidden, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onPreeditUpdated, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, setSize, shouldRenderInDarkMode, tick, validate
-
Field Details
-
DEFAULT_OFF_IMAGE
-
DEFAULT_ON_IMAGE
-
DEFAULT_FOCUS_IMAGE
-
onImage
-
offImage
-
focusImage
-
label
-
isOn
protected boolean isOn -
onToggle
-
color
protected int color -
darkmodeColor
protected int darkmodeColor
-
-
Constructor Details
-
WToggleButton
public WToggleButton()Constructs a toggle button with default images and no label. -
WToggleButton
public WToggleButton(net.minecraft.network.chat.Component label) Constructs a toggle button with default images.- Parameters:
label- the button label
-
WToggleButton
public WToggleButton(net.minecraft.resources.Identifier onImage, net.minecraft.resources.Identifier offImage) Constructs a toggle button with custom images and no label.- Parameters:
onImage- the toggled on imageoffImage- the toggled off image
-
WToggleButton
public WToggleButton(net.minecraft.resources.Identifier onImage, net.minecraft.resources.Identifier offImage, net.minecraft.network.chat.Component label) Constructs a toggle button with custom images.- Parameters:
onImage- the toggled on imageoffImage- the toggled off imagelabel- the button label
-
WToggleButton
-
WToggleButton
-
-
Method Details
-
paint
@Environment(CLIENT) public void paint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Description copied from class:WWidgetPaints this widget. -
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
canFocus
-
onClick
@Environment(CLIENT) public InputResult onClick(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) Description copied from class:WWidgetNotifies this widget that the mouse has been pressed and released, both while inside its bounds.- Overrides:
onClickin classWWidget- Parameters:
click- the click data whose coordinates are in widget space ((0, 0) is the top-left point of this widget)doubled-trueif this is a double click,falseotherwise- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onKeyPressed
Description copied from class:WWidgetNotifies this widget that a key has been pressed.- Overrides:
onKeyPressedin classWWidget- Parameters:
input- the key input- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onToggle
protected void onToggle(boolean on) -
getToggle
public boolean getToggle() -
setToggle
public void setToggle(boolean on) -
getOnToggle
-
setOnToggle
-
getLabel
-
setLabel
-
setColor
-
getOnImage
-
setOnImage
-
getOffImage
-
setOffImage
-
getFocusImage
-
setFocusImage
-
addNarrations
@Environment(CLIENT) public void addNarrations(net.minecraft.client.gui.narration.NarrationElementOutput builder) Description copied from class:WWidgetAdds the narrations of this widget to a narration builder. Narrations will only apply if this widget is narratable.The widget needs to be focusable or hoverable, and also be focused/hovered for narrations to be added.
- Overrides:
addNarrationsin classWWidget- Parameters:
builder- the narration builder, cannot be null
-