Class WButton
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WButton
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanFocus()Tests whether this widget can have the focus in the GUI.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).@Nullable IcongetIcon()Gets the icon of this button.net.minecraft.text.TextgetLabel()@Nullable RunnableGets the click handler of this button.booleanonClick(int x, int y, int button)Notifies this widget that the mouse has been pressed and released, both while inside its bounds.voidonKeyPressed(int ch, int key, int modifiers)Notifies this widget that a key has been pressed.voidpaint(net.minecraft.client.util.math.MatrixStack matrices, int x, int y, int mouseX, int mouseY)Paints this widget.setAlignment(HorizontalAlignment alignment)setEnabled(boolean enabled)Sets the icon of this button.setLabel(net.minecraft.text.Text label)setOnClick(@Nullable Runnable onClick)Sets the click handler of this button.voidsetSize(int x, int y)Sets the size of this widget.Methods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addPainters, addTooltip, createPeers, cycleFocus, getAbsoluteX, getAbsoluteY, getHeight, getHost, getParent, getWidth, getX, getY, hit, isActivationKey, isFocused, isWithinBounds, onCharTyped, onFocusGained, onFocusLost, onHidden, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setLocation, setParent, tick, validate
-
Field Details
-
color
protected int color -
darkmodeColor
protected int darkmodeColor -
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
public WButton(net.minecraft.text.Text label)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: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. -
paint
@Environment(CLIENT) public void paint(net.minecraft.client.util.math.MatrixStack matrices, int x, int y, int mouseX, int mouseY)Description copied from class:WWidgetPaints this widget. -
setSize
public void setSize(int x, int y)Description copied from class:WWidgetSets the size of this widget.Overriding methods may restrict one of the dimensions to be a constant value, for example
super.setSize(x, 20). -
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
@Environment(CLIENT) public void onKeyPressed(int ch, int key, int modifiers)Description copied from class:WWidgetNotifies this widget that a key has been pressed.- Overrides:
onKeyPressedin classWWidgetkey- the GLFW scancode of the key
-
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
public net.minecraft.text.Text getLabel() -
setLabel
-
getAlignment
-
setAlignment
-
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
-