Class AbstractWidget

java.lang.Object
net.minecraft.client.gui.components.AbstractWidget
All Implemented Interfaces:
GuiEventListener, Renderable, TabOrderedElement, LayoutElement, NarratableEntry, NarrationSupplier
Direct Known Subclasses:
AbstractButton, AbstractScrollArea, AbstractSliderButton, AbstractStringWidget, EditBox, GameModeSwitcherScreen.GameModeSlot, ImageWidget, ItemDisplayWidget, LoadingDotsWidget, OverlayRecipeComponent.OverlayRecipeButton, PlayerSkinWidget, RecipeButton, StateSwitchingButton, TabButton

public abstract class AbstractWidget extends Object implements Renderable, GuiEventListener, LayoutElement, NarratableEntry
  • 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

      private Component 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

      private final WidgetTooltipHolder tooltip
    • UNSET_FG_COLOR

      public static final int UNSET_FG_COLOR
      See Also:
    • packedFGColor

      protected int packedFGColor
  • Constructor Details

    • AbstractWidget

      public AbstractWidget(int pX, int pY, int pWidth, int pHeight, Component pMessage)
  • Method Details

    • getHeight

      public int getHeight()
      Specified by:
      getHeight in interface LayoutElement
    • render

      public final void render(GuiGraphics p_282421_, int p_93658_, int p_93659_, float p_93660_)
      Description copied from interface: Renderable
      Renders the graphical user interface (GUI) element.
      Specified by:
      render in interface Renderable
      Parameters:
      p_282421_ - the GuiGraphics object used for rendering.
      p_93658_ - the x-coordinate of the mouse cursor.
      p_93659_ - the y-coordinate of the mouse cursor.
      p_93660_ - the partial tick time.
    • setTooltip

      public void setTooltip(@Nullable Tooltip pTooltip)
    • setTooltipDelay

      public void setTooltipDelay(Duration pTooltipDelay)
    • createNarrationMessage

      protected MutableComponent createNarrationMessage()
    • wrapDefaultNarrationMessage

      public static MutableComponent wrapDefaultNarrationMessage(Component pMessage)
    • renderWidget

      protected abstract void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick)
    • renderScrollingString

      public static void renderScrollingString(GuiGraphics pGuiGraphics, Font pFont, Component pText, int pMinX, int pMinY, int pMaxX, int pMaxY, int pColor)
    • renderScrollingString

      public static void renderScrollingString(GuiGraphics pGuiGraphics, Font pFont, Component pText, int pCenterX, int pMinX, int pMinY, int pMaxX, int pMaxY, int pColor)
    • renderScrollingString

      protected void renderScrollingString(GuiGraphics pGuiGraphics, Font pFont, int pPadding, int pColor)
    • onClick

      public void onClick(MouseButtonEvent pEvent, boolean pIsDoubleClick)
    • onRelease

      public void onRelease(MouseButtonEvent pEvent)
    • onDrag

      protected void onDrag(MouseButtonEvent pEvent, double pMouseX, double pMouseY)
    • mouseClicked

      public boolean mouseClicked(MouseButtonEvent p_447133_, boolean p_434606_)
      Specified by:
      mouseClicked in interface GuiEventListener
    • mouseReleased

      public boolean mouseReleased(MouseButtonEvent p_446092_)
      Specified by:
      mouseReleased in interface GuiEventListener
    • isValidClickButton

      protected boolean isValidClickButton(MouseButtonInfo pButtonInfo)
    • mouseDragged

      public boolean mouseDragged(MouseButtonEvent p_445646_, double p_93645_, double p_93646_)
      Specified by:
      mouseDragged in interface GuiEventListener
    • nextFocusPath

      @Nullable public ComponentPath nextFocusPath(FocusNavigationEvent p_265640_)
      Description copied from interface: GuiEventListener
      Retrieves the next focus path based on the given focus navigation event.

      Specified by:
      nextFocusPath in interface GuiEventListener
      Parameters:
      p_265640_ - the focus navigation event.
      Returns:
      the next focus path as a ComponentPath, or null if there is no next focus path.
    • isMouseOver

      public boolean isMouseOver(double pMouseX, double pMouseY)
      Description copied from interface: GuiEventListener
      Checks if the given mouse coordinates are over the GUI element.

      Specified by:
      isMouseOver in interface GuiEventListener
      Parameters:
      pMouseX - the X coordinate of the mouse.
      pMouseY - the Y coordinate of the mouse.
      Returns:
      true if the mouse is over the GUI element, false otherwise.
    • playDownSound

      public void playDownSound(SoundManager pHandler)
    • playButtonClickSound

      public static void playButtonClickSound(SoundManager pSoundManager)
    • getWidth

      public int getWidth()
      Specified by:
      getWidth in interface LayoutElement
    • setWidth

      public void setWidth(int pWidth)
    • setHeight

      public void setHeight(int pHeight)
    • setAlpha

      public void setAlpha(float pAlpha)
    • setMessage

      public void setMessage(Component pMessage)
    • getMessage

      public Component getMessage()
    • isFocused

      public boolean isFocused()
      Specified by:
      isFocused in interface GuiEventListener
    • isHovered

      public boolean isHovered()
    • isHoveredOrFocused

      public boolean isHoveredOrFocused()
    • isActive

      public boolean isActive()
      Specified by:
      isActive in interface NarratableEntry
    • setFocused

      public void setFocused(boolean pFocused)
      Description copied from interface: GuiEventListener
      Sets the focus state of the GUI element.
      Specified by:
      setFocused in interface GuiEventListener
      Parameters:
      pFocused - true to apply focus, false to remove focus
    • getFGColor

      public int getFGColor()
    • setFGColor

      public void setFGColor(int color)
    • clearFGColor

      public void clearFGColor()
    • narrationPriority

      public NarratableEntry.NarrationPriority narrationPriority()
      Specified by:
      narrationPriority in interface NarratableEntry
    • updateNarration

      public final void updateNarration(NarrationElementOutput p_259921_)
      Description copied from interface: NarrationSupplier
      Updates the narration output with the current narration information.
      Specified by:
      updateNarration in interface NarrationSupplier
      Parameters:
      p_259921_ - the output to update with narration information.
    • updateWidgetNarration

      protected abstract void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput)
    • defaultButtonNarrationText

      protected void defaultButtonNarrationText(NarrationElementOutput pNarrationElementOutput)
    • getX

      public int getX()
      Specified by:
      getX in interface LayoutElement
    • setX

      public void setX(int pX)
      Specified by:
      setX in interface LayoutElement
    • getY

      public int getY()
      Specified by:
      getY in interface LayoutElement
    • setY

      public void setY(int pY)
      Specified by:
      setY in interface LayoutElement
    • getRight

      public int getRight()
    • getBottom

      public int getBottom()
    • visitWidgets

      public void visitWidgets(Consumer<AbstractWidget> p_265566_)
      Specified by:
      visitWidgets in interface LayoutElement
    • setSize

      public void setSize(int pWidth, int pHeight)
    • getRectangle

      public ScreenRectangle getRectangle()
      Specified by:
      getRectangle in interface GuiEventListener
      Specified by:
      getRectangle in interface LayoutElement
    • areCoordinatesInRectangle

      private boolean areCoordinatesInRectangle(double pX, double pY)
    • setRectangle

      public void setRectangle(int pWidth, int pHeight, int pX, int pY)
    • getTabOrderGroup

      public int getTabOrderGroup()
      Specified by:
      getTabOrderGroup in interface TabOrderedElement
    • setTabOrderGroup

      public void setTabOrderGroup(int pTabOrderGroup)