Class WButton
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WButton
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HorizontalAlignmentprotected intprotected intThe size (width/height) of this button's icon in pixels. -
Constructor Summary
ConstructorsConstructorDescriptionWButton()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 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).getIcon()Gets the icon of this button.intGets the current height / width of the icon.@Nullable net.minecraft.network.chat.ComponentgetLabel()Gets the click handler of this button.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.voidpaint(net.minecraft.client.gui.GuiGraphicsExtractor 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.setLabel(net.minecraft.network.chat.Component label) setOnClick(@Nullable Runnable onClick) Sets the click handler of this button.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
-
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
-
WButton
Constructs a button with a label.- Parameters:
label- the label
-
WButton
-
-
Method Details
-
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
canFocus
-
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. -
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.
-
getOnClick
-
setOnClick
-
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
-
setIcon
-
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
-