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, Text label) Constructs a toggle button with custom images.WToggleButton(Text label) Constructs a toggle button with default images.WToggleButton(Identifier onImage, Identifier offImage) Constructs a toggle button with custom images and no label.WToggleButton(Identifier onImage, Identifier offImage, Text label) Constructs a toggle button with custom images. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(NarrationMessageBuilder 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).getLabel()booleanonClick(int x, int y, int button) Notifies this widget that the mouse has been pressed and released, both while inside its bounds.onKeyPressed(int ch, int key, int modifiers) Notifies this widget that a key has been pressed.protected voidonToggle(boolean on) voidpaint(DrawContext 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 io.github.cottonmc.cotton.gui.widget.WWidget
addPainters, addTooltip, 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, 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
Constructs a toggle button with default images.- Parameters:
label- the button label
-
WToggleButton
Constructs a toggle button with custom images and no label.- Parameters:
onImage- the toggled on imageoffImage- the toggled off image
-
WToggleButton
Constructs a toggle button with custom images.- Parameters:
onImage- the toggled on imageoffImage- the toggled off imagelabel- the button label
-
WToggleButton
Constructs a toggle button with custom images and no label.- Parameters:
onImage- the toggled on imageoffImage- the toggled off image- Since:
- 3.0.0
-
WToggleButton
Constructs a toggle button with custom images.- Parameters:
onImage- the toggled on imageoffImage- the toggled off imagelabel- the button label- Since:
- 3.0.0
-
-
Method Details
-
paint
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
public boolean canFocus()Description copied from class:WWidgetTests whether this widget can have the focus in the GUI. -
onClick
Description copied from class:WWidgetNotifies this widget that the mouse has been pressed and released, both while inside its bounds.- Overrides:
onClickin classWWidget- Parameters:
x- The X coordinate of the event, in widget-space (0 is the left edge of this widget)y- The Y coordinate of the event, in widget-space (0 is the top edge of this widget)button- The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)- 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:
key- the GLFW scancode of the key- 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
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
-