Class WButton
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WButton
-
Field Summary
Modifier and TypeFieldDescriptionprotected HorizontalAlignment
protected int
protected int
The size (width/height) of this button's icon in pixels. -
Constructor Summary
ConstructorDescriptionWButton()
Constructs a button with no label and no icon.Constructs a button with an icon.Constructs a button with an icon and a label.Constructs a button with a label. -
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)
.getIcon()
Gets the icon of this button.int
Gets the current height / width of the icon.getLabel()
Gets the click handler of this button.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.void
paint
(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.setAlignment
(HorizontalAlignment alignment) setEnabled
(boolean enabled) Sets the icon of this button.setIconSize
(int iconSize) Sets the new size of the icon.setOnClick
(@Nullable Runnable onClick) Sets the click handler of this button.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
-
color
protected int color -
iconSize
protected int iconSizeThe size (width/height) of this button's icon in pixels.- Since:
- 6.4.0
-
alignment
-
-
Constructor Details
-
WButton
public WButton()Constructs a button with no label and no icon. -
WButton
Constructs a button with an icon.- Parameters:
icon
- the icon- Since:
- 2.2.0
-
WButton
Constructs a button with a label.- Parameters:
label
- the label
-
WButton
Constructs a button with an icon and a label.- Parameters:
icon
- the iconlabel
- the label- Since:
- 2.2.0
-
-
Method Details
-
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. -
paint
Description copied from class:WWidget
Paints this widget. -
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.
-
getOnClick
Gets the click handler of this button.- Returns:
- the click handler
- Since:
- 2.2.0
-
setOnClick
Sets the click handler of this button.- Parameters:
onClick
- the new click handler- Returns:
- this button
-
isEnabled
public boolean isEnabled() -
setEnabled
-
getLabel
-
setLabel
-
getAlignment
-
setAlignment
-
getIconSize
public int getIconSize()Gets the current height / width of the icon.- Returns:
- the current height / width of the icon
- Since:
- 6.4.0
-
setIconSize
Sets the new size of the icon.- Parameters:
iconSize
- the new height and width of the icon- Returns:
- this button
- Since:
- 6.4.0
-
getIcon
Gets the icon of this button.- Returns:
- the icon
- Since:
- 2.2.0
-
setIcon
Sets the icon of this button.- Parameters:
icon
- the new icon- Returns:
- this button
- Since:
- 2.2.0
-
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
-