Class AbstractWidget
java.lang.Object
net.minecraft.client.gui.components.AbstractWidget
- All Implemented Interfaces:
GuiEventListener,Renderable,TabOrderedElement,LayoutElement,NarratableEntry,NarrationSupplier,IAbstractWidgetExtension
- Direct Known Subclasses:
AbstractButton,AbstractContainerWidget,AbstractScrollWidget,AbstractSliderButton,AbstractStringWidget,EditBox,GameModeSwitcherScreen.GameModeSlot,ImageWidget,LoadingDotsWidget,OverlayRecipeComponent.OverlayRecipeButton,PlayerSkinWidget,RecipeButton,StateSwitchingButton,TabButton
public abstract class AbstractWidget
extends Object
implements Renderable, GuiEventListener, LayoutElement, NarratableEntry, IAbstractWidgetExtension
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.client.gui.narration.NarratableEntry
NarratableEntry.NarrationPriority -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanprotected floatprivate booleanprotected intprotected booleanprivate Componentprivate static final doubleprotected intprivate static final doubleprivate intprivate final WidgetTooltipHolderstatic final intbooleanprotected intprivate intprivate intFields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
DOUBLE_CLICK_THRESHOLD_MS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected booleanclicked(double mouseX, double mouseY) protected MutableComponentprotected voiddefaultButtonNarrationText(NarrationElementOutput narrationElementOutput) intintintintgetRight()intintgetWidth()intgetX()intgetY()booleanisActive()booleanbooleanbooleanbooleanisMouseOver(double mouseX, double mouseY) Checks if the given mouse coordinates are over the GUI element.protected booleanisValidClickButton(int button) booleanmouseClicked(double mouseX, double mouseY, int button) Called when a mouse button is clicked within the GUI element.booleanmouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) Called when the mouse is dragged within the GUI element.booleanmouseReleased(double mouseX, double mouseY, int button) Called when a mouse button is released within the GUI element.Retrieves the next focus path based on the given focus navigation event.voidonClick(double mouseX, double mouseY) Deprecated.protected voidonDrag(double mouseX, double mouseY, double dragX, double dragY) voidonRelease(double mouseX, double mouseY) voidplayDownSound(SoundManager handler) final voidrender(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) Renders the graphical user interface (GUI) element.protected voidrenderScrollingString(GuiGraphics guiGraphics, Font font, int width, int color) static voidrenderScrollingString(GuiGraphics guiGraphics, Font font, Component text, int minX, int minY, int maxX, int maxY, int color) static voidrenderScrollingString(GuiGraphics guiGraphics, Font font, Component text, int centerX, int minX, int minY, int maxX, int maxY, int color) protected abstract voidrenderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) voidsetAlpha(float alpha) voidsetFGColor(int color) voidsetFocused(boolean focused) Sets the focus state of the GUI element.voidsetHeight(int height) voidsetMessage(Component message) voidsetRectangle(int width, int height, int x, int y) voidsetSize(int width, int height) voidsetTabOrderGroup(int tabOrderGroup) voidsetTooltip(Tooltip tooltip) voidsetTooltipDelay(Duration tooltipDelay) voidsetWidth(int width) voidsetX(int x) voidsetY(int y) final voidupdateNarration(NarrationElementOutput narrationElementOutput) Updates the narration output with the current narration information.protected abstract voidupdateWidgetNarration(NarrationElementOutput narrationElementOutput) voidvisitWidgets(Consumer<AbstractWidget> consumer) static MutableComponentwrapDefaultNarrationMessage(Component message) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
charTyped, getCurrentFocusPath, keyPressed, keyReleased, mouseMoved, mouseScrolledMethods inherited from interface net.neoforged.neoforge.client.extensions.IAbstractWidgetExtension
onClickMethods inherited from interface net.minecraft.client.gui.layouts.LayoutElement
setPosition
-
Field Details
-
PERIOD_PER_SCROLLED_PIXEL
private static final double PERIOD_PER_SCROLLED_PIXEL- See Also:
-
MIN_SCROLL_PERIOD
private static final double MIN_SCROLL_PERIOD- See Also:
-
width
protected int width -
height
protected int height -
x
private int x -
y
private int y -
message
-
isHovered
protected boolean isHovered -
active
public boolean active -
visible
public boolean visible -
alpha
protected float alpha -
tabOrderGroup
private int tabOrderGroup -
focused
private boolean focused -
tooltip
-
UNSET_FG_COLOR
public static final int UNSET_FG_COLOR- See Also:
-
packedFGColor
protected int packedFGColor
-
-
Constructor Details
-
AbstractWidget
-
-
Method Details
-
getHeight
public int getHeight()- Specified by:
getHeightin interfaceLayoutElement
-
render
Renders the graphical user interface (GUI) element.- Specified by:
renderin interfaceRenderable- Parameters:
guiGraphics- the GuiGraphics object used for rendering.mouseX- the x-coordinate of the mouse cursor.mouseY- the y-coordinate of the mouse cursor.partialTick- the partial tick time.
-
setTooltip
-
getTooltip
-
setTooltipDelay
-
createNarrationMessage
-
wrapDefaultNarrationMessage
-
renderWidget
protected abstract void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) -
renderScrollingString
public static void renderScrollingString(GuiGraphics guiGraphics, Font font, Component text, int minX, int minY, int maxX, int maxY, int color) -
renderScrollingString
public static void renderScrollingString(GuiGraphics guiGraphics, Font font, Component text, int centerX, int minX, int minY, int maxX, int maxY, int color) -
renderScrollingString
-
onClick
Deprecated.Neo: UseIAbstractWidgetExtension.onClick(double, double, int)instead. -
onRelease
public void onRelease(double mouseX, double mouseY) -
onDrag
protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) -
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button) Called when a mouse button is clicked within the GUI element.- Specified by:
mouseClickedin interfaceGuiEventListener- Parameters:
mouseX- the X coordinate of the mouse.mouseY- the Y coordinate of the mouse.button- the button that was clicked.- Returns:
trueif the event is consumed,falseotherwise.
-
mouseReleased
public boolean mouseReleased(double mouseX, double mouseY, int button) Called when a mouse button is released within the GUI element.- Specified by:
mouseReleasedin interfaceGuiEventListener- Parameters:
mouseX- the X coordinate of the mouse.mouseY- the Y coordinate of the mouse.button- the button that was released.- Returns:
trueif the event is consumed,falseotherwise.
-
isValidClickButton
protected boolean isValidClickButton(int button) -
mouseDragged
public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) Called when the mouse is dragged within the GUI element.- Specified by:
mouseDraggedin interfaceGuiEventListener- Parameters:
mouseX- the X coordinate of the mouse.mouseY- the Y coordinate of the mouse.button- the button that is being dragged.dragX- the X distance of the drag.dragY- the Y distance of the drag.- Returns:
trueif the event is consumed,falseotherwise.
-
clicked
protected boolean clicked(double mouseX, double mouseY) -
isMouseOver
public boolean isMouseOver(double mouseX, double mouseY) Checks if the given mouse coordinates are over the GUI element.- Specified by:
isMouseOverin interfaceGuiEventListener- Parameters:
mouseX- the X coordinate of the mouse.mouseY- the Y coordinate of the mouse.- Returns:
trueif the mouse is over the GUI element,falseotherwise.
-
playDownSound
-
getWidth
public int getWidth()- Specified by:
getWidthin interfaceLayoutElement
-
setWidth
public void setWidth(int width) -
setHeight
public void setHeight(int height) -
setAlpha
public void setAlpha(float alpha) -
setMessage
-
getMessage
-
isFocused
public boolean isFocused()- Specified by:
isFocusedin interfaceGuiEventListener
-
isHovered
public boolean isHovered() -
isHoveredOrFocused
public boolean isHoveredOrFocused() -
isActive
public boolean isActive()- Specified by:
isActivein interfaceNarratableEntry
-
setFocused
public void setFocused(boolean focused) Sets the focus state of the GUI element.- Specified by:
setFocusedin interfaceGuiEventListener- Parameters:
focused-trueto apply focus,falseto remove focus
-
getFGColor
public int getFGColor() -
setFGColor
public void setFGColor(int color) -
clearFGColor
public void clearFGColor() -
narrationPriority
- Specified by:
narrationPriorityin interfaceNarratableEntry
-
updateNarration
Updates the narration output with the current narration information.- Specified by:
updateNarrationin interfaceNarrationSupplier- Parameters:
narrationElementOutput- the output to update with narration information.
-
updateWidgetNarration
-
defaultButtonNarrationText
-
getX
public int getX()- Specified by:
getXin interfaceLayoutElement
-
setX
public void setX(int x) - Specified by:
setXin interfaceLayoutElement
-
getY
public int getY()- Specified by:
getYin interfaceLayoutElement
-
setY
public void setY(int y) - Specified by:
setYin interfaceLayoutElement
-
getRight
public int getRight() -
getBottom
public int getBottom() -
visitWidgets
- Specified by:
visitWidgetsin interfaceLayoutElement
-
setSize
public void setSize(int width, int height) -
getRectangle
- Specified by:
getRectanglein interfaceGuiEventListener- Specified by:
getRectanglein interfaceLayoutElement
-
setRectangle
public void setRectangle(int width, int height, int x, int y) -
getTabOrderGroup
public int getTabOrderGroup()- Specified by:
getTabOrderGroupin interfaceTabOrderedElement
-
setTabOrderGroup
public void setTabOrderGroup(int tabOrderGroup)
-
IAbstractWidgetExtension.onClick(double, double, int)instead.