Class GuiButton
java.lang.Object
codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry<T>
codechicken.lib.gui.modular.elements.GuiElement<GuiButton>
codechicken.lib.gui.modular.elements.GuiButton
- All Implemented Interfaces:
ElementEvents,GuiParent<GuiButton>,TooltipHandler<GuiButton>
Created by brandon3055 on 28/08/2023
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intFields inherited from class codechicken.lib.gui.modular.elements.GuiElement
hoverTime, initialized -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GuiButtonflatColourButton(@NotNull GuiParent<?> parent, @Nullable Supplier<net.minecraft.network.chat.Component> label, Function<Boolean, Integer> buttonColour) Super simple button that is just a coloured rectangle with a label.static GuiButtonflatColourButton(@NotNull GuiParent<?> parent, @Nullable Supplier<net.minecraft.network.chat.Component> label, Function<Boolean, Integer> buttonColour, @Nullable Function<Boolean, Integer> borderColour) Super simple button that is just a coloured rectangle with a label.getLabel()net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>booleanbooleanbooleanmouseClicked(double mouseX, double mouseY, int button) Override this method to implement handling for the mouseClicked event.booleanmouseReleased(double mouseX, double mouseY, int button, boolean consumed) Root handler for mouseReleased event.This event is fired immediately when this button is left-clicked.This event is fired immediately when this button is clicked with the specified mouse button.This event is fired when the button is pressed and then released using the left mosue button.This event is fired when the button is pressed and then released using the specified mouse button.setDisabled(boolean disabled) Allows set the disabled status of this button Note: This is not the same asGuiElement.setEnabled(boolean)the "enabled" allows you to completely disable an element.setDisabled(Supplier<Boolean> disabled) Allows you to install a suppler that controls the disabled state of this button.When creating buttons with labels, use this method to store a reference to the label in the button fore easy retrival later.setPressSound(net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> pressSound) Sets the sound to be played when this button is pressed.setReleaseSound(net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> releaseSound) Sets the sound to be played when this button is released.setResetHoverOnPress(boolean resetHoverOnPress) By default, hover time is reset when button is pressed.setToggleMode(@Nullable Supplier<Boolean> toggleState) Allows this button to be used as a toggle or radio button.booleanstatic GuiButtonCreates a new gui button that looks and acts exactly like a standard vanilla button.static GuiButtonvanilla(@NotNull GuiParent<?> parent, @Nullable net.minecraft.network.chat.Component label, Runnable onClick) Creates a new gui button that looks and acts exactly like a standard vanilla button.static GuiButtonvanillaAnimated(@NotNull GuiParent<?> parent, @Nullable Supplier<net.minecraft.network.chat.Component> label) Creates a vanilla button with a "press" animation.static GuiButtonvanillaAnimated(@NotNull GuiParent<?> parent, @Nullable Supplier<net.minecraft.network.chat.Component> label, Runnable onPress) Creates a vanilla button with a "press" animation.static GuiButtonvanillaAnimated(@NotNull GuiParent<?> parent, net.minecraft.network.chat.Component label) Creates a vanilla button with a "press" animation.static GuiButtonvanillaAnimated(@NotNull GuiParent<?> parent, net.minecraft.network.chat.Component label, Runnable onPress) Creates a vanilla button with a "press" animation.Methods inherited from class codechicken.lib.gui.modular.elements.GuiElement
addChild, addJeiDropTargets, addJeiExclusions, adoptChild, applyQueuedChildUpdates, blockMouseEvents, blockMouseOver, bringChildToForeground, font, getChildren, getCombinedElementDepth, getJeiDropConsumer, getModularGui, getParent, getTooltip, getTooltipDelay, hoverTime, initElement, isDescendantOf, isEnabled, isJeiDropTarget, isJeiExcluded, isMouseOver, isOpaque, isRemoved, isTooltipEnabled, jeiExclude, mc, onScreenInit, removeChild, render, renderChild, renderOverlay, scaledScreenHeight, scaledScreenWidth, sendChildToBackground, sendChildToIndex, setEnabled, setEnabled, setEnableToolTip, setJeiDropTarget, setJeiExcluded, setOpaque, setRenderCull, setTooltip, setTooltipDelay, setZStacking, showToolTip, tick, toString, updateMouseOver, updateScreenData, zStackingMethods inherited from class codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry
addBoundsToRect, clearConstraints, clearGeometryCache, constrain, get, getChildBounds, getEnclosingRect, getParent, getPosition, getRectangle, placeInside, placeInside, placeOutside, placeOutside, setHeight, setPos, setSize, setWidth, setXPos, setYPos, strictMode, validate, xCenter, xMax, xMin, xSize, yCenter, yMax, yMin, ySizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface codechicken.lib.gui.modular.lib.ElementEvents
charTyped, charTyped, keyPressed, keyPressed, keyReleased, keyReleased, mouseClicked, mouseMoved, mouseReleased, mouseScrolled, mouseScrolledMethods inherited from interface codechicken.lib.gui.modular.lib.geometry.GuiParent
addChild, getValueMethods inherited from interface codechicken.lib.gui.modular.lib.TooltipHandler
renderTooltip, setTooltip, setTooltip, setTooltip, setTooltipSingle, setTooltipSingle
-
Field Details
-
LEFT_CLICK
public static final int LEFT_CLICK- See Also:
-
RIGHT_CLICK
public static final int RIGHT_CLICK- See Also:
-
MIDDLE_CLICK
public static final int MIDDLE_CLICK- See Also:
-
-
Constructor Details
-
GuiButton
In its default state this is a blank, invisible element that can fire callbacks when pressed. To make an actual usable button, ether use one of the builtin static create methods, Or add your own elements to make this button look and function in a way that meets your needs.- Parameters:
parent- parentGuiParent.
-
-
Method Details
-
vanilla
public static GuiButton vanilla(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable net.minecraft.network.chat.Component label, Runnable onClick) Creates a new gui button that looks and acts exactly like a standard vanilla button. -
vanilla
public static GuiButton vanilla(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable net.minecraft.network.chat.Component label) Creates a new gui button that looks and acts exactly like a standard vanilla button. -
vanillaAnimated
public static GuiButton vanillaAnimated(@NotNull @NotNull GuiParent<?> parent, net.minecraft.network.chat.Component label, Runnable onPress) Creates a vanilla button with a "press" animation. -
vanillaAnimated
public static GuiButton vanillaAnimated(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable Supplier<net.minecraft.network.chat.Component> label, Runnable onPress) Creates a vanilla button with a "press" animation. -
vanillaAnimated
public static GuiButton vanillaAnimated(@NotNull @NotNull GuiParent<?> parent, net.minecraft.network.chat.Component label) Creates a vanilla button with a "press" animation. -
vanillaAnimated
public static GuiButton vanillaAnimated(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable Supplier<net.minecraft.network.chat.Component> label) Creates a vanilla button with a "press" animation. -
flatColourButton
public static GuiButton flatColourButton(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable Supplier<net.minecraft.network.chat.Component> label, Function<Boolean, Integer> buttonColour) Super simple button that is just a coloured rectangle with a label. -
flatColourButton
public static GuiButton flatColourButton(@NotNull @NotNull GuiParent<?> parent, @Nullable @Nullable Supplier<net.minecraft.network.chat.Component> label, Function<Boolean, Integer> buttonColour, @Nullable @Nullable Function<Boolean, Integer> borderColour) Super simple button that is just a coloured rectangle with a label. -
setLabel
When creating buttons with labels, use this method to store a reference to the label in the button fore easy retrival later.- Parameters:
label- The button label.
-
getLabel
- Returns:
- The buttons label element, If it has one.
-
setResetHoverOnPress
By default, hover time is reset when button is pressed. THis allows you to disable that functionality to the tooltip will remain open when button is pressed. -
onClick
This event is fired immediately when this button is left-clicked. This is the logic used by most vanilla gui buttons.- See Also:
-
onClick
This event is fired immediately when this button is clicked with the specified mouse button. This is the logic used by most vanilla gui buttons. Note: You can apply one listener per mouse button.- See Also:
-
onPress
This event is fired when the button is pressed and then released using the left mosue button. The event is only fired if the cursor is still over the button when left click is released. This is the standard logic for most buttons in the world, but not vanillas. Note: You can apply one listener per mouse button.- See Also:
-
onPress
This event is fired when the button is pressed and then released using the specified mouse button. The event is only fired if the cursor is still over the button when left click is released. This is the standard logic for most buttons in the world, but not vanillas.- See Also:
-
setDisabled
Allows set the disabled status of this button Note: This is not the same asGuiElement.setEnabled(boolean)the "enabled" allows you to completely disable an element. This "disabled" status is specific toGuiButton, When disabled via this method a button is still visible but greyed out / not clickable. -
setDisabled
Allows you to install a suppler that controls the disabled state of this button. Note: This is not the same asGuiElement.setEnabled(Supplier)the "enabled" allows you to completely disable an element. This "disabled" status is specific toGuiButton, When disabled via this method a button is still visible but greyed out / not clickable. -
setToggleMode
Allows this button to be used as a toggle or radio button. This method allows you to install a suppler that controls the current "selected / toggled" state.- Parameters:
toggleState- supplier that indicates weather or not this button should currently render as pressed/selected.
-
isDisabled
public boolean isDisabled()- Returns:
- the "disabled" status.
- See Also:
-
isPressed
public boolean isPressed()- Returns:
- true if this button is currently pressed by the user (left click held down on button)
-
toggleState
public boolean toggleState() -
setPressSound
public GuiButton setPressSound(net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> pressSound) Sets the sound to be played when this button is pressed. -
setReleaseSound
public GuiButton setReleaseSound(net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> releaseSound) Sets the sound to be played when this button is released. -
getPressSound
public net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> getPressSound() -
getReleaseSound
public net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> getReleaseSound() -
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button) Description copied from interface:ElementEventsOverride this method to implement handling for the mouseClicked event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can overrideElementEvents.mouseClicked(double, double, int, boolean)Note: You do not need to call super when overriding this interface method.
- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionbutton- Mouse Button- Returns:
- true to consume event.
-
mouseReleased
public boolean mouseReleased(double mouseX, double mouseY, int button, boolean consumed) Description copied from interface:ElementEventsRoot handler for mouseReleased event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of mouseReleased handling should be implemented viaElementEvents.mouseReleased(double, double, int)Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.
- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionbutton- Mouse Buttonconsumed- Will be true if this action has already been consumed.- Returns:
- true if this event has been consumed.
-