Class WToggleButton
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WToggleButton
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs 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 TypeMethodDescriptionvoid
addNarrations
(NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.boolean
canFocus()
Tests whether this widget can have the focus in the GUI.boolean
Checks whether this widget can be resized usingWWidget.setSize(int, int)
.getLabel()
boolean
onClick
(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 void
onToggle
(boolean on) void
paint
(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) void
setToggle
(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:WWidget
Paints this widget. -
canResize
public boolean canResize()Description copied from class:WWidget
Checks whether this widget can be resized usingWWidget.setSize(int, int)
. -
canFocus
public boolean canFocus()Description copied from class:WWidget
Tests whether this widget can have the focus in the GUI. -
onClick
Description copied from class:WWidget
Notifies this widget that the mouse has been pressed and released, both while inside its bounds.- Overrides:
onClick
in 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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
onKeyPressed
Description copied from class:WWidget
Notifies this widget that a key has been pressed.- Overrides:
onKeyPressed
in classWWidget
- Parameters:
key
- the GLFW scancode of the key- Returns:
InputResult.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
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:WWidget
Adds 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:
addNarrations
in classWWidget
- Parameters:
builder
- the narration builder, cannot be null
-