Class AbstractWidget

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

public abstract class AbstractWidget extends Object implements LayoutElement, Renderable, GuiEventListener, NarratableEntry
  • Field Details

    • width

      protected int width
    • height

      protected int height
    • x

      private int x
    • y

      private int y
    • message

      protected 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 x, int y, int width, int height, Component message)
  • Method Details

    • getHeight

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

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

      protected void handleCursor(GuiGraphics graphics)
    • setTooltip

      public void setTooltip(@Nullable Tooltip tooltip)
    • setTooltipDelay

      public void setTooltipDelay(Duration delay)
    • createNarrationMessage

      protected MutableComponent createNarrationMessage()
    • wrapDefaultNarrationMessage

      public static MutableComponent wrapDefaultNarrationMessage(Component message)
    • renderWidget

      protected abstract void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float a)
    • renderScrollingStringOverContents

      public void renderScrollingStringOverContents(ActiveTextCollector output, Component message, int margin)
    • onClick

      public void onClick(MouseButtonEvent event, boolean doubleClick)
    • onRelease

      public void onRelease(MouseButtonEvent event)
    • onDrag

      protected void onDrag(MouseButtonEvent event, double dx, double dy)
    • mouseClicked

      public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick)
      Specified by:
      mouseClicked in interface GuiEventListener
    • mouseReleased

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

      protected boolean isValidClickButton(MouseButtonInfo buttonInfo)
    • mouseDragged

      public boolean mouseDragged(MouseButtonEvent event, double dx, double dy)
      Specified by:
      mouseDragged in interface GuiEventListener
    • nextFocusPath

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

      Specified by:
      nextFocusPath in interface GuiEventListener
      Parameters:
      navigationEvent - 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 mouseX, double mouseY)
      Description copied from interface: GuiEventListener
      Checks if the given mouse coordinates are over the GUI element.

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

      public void playDownSound(SoundManager soundManager)
    • playButtonClickSound

      public static void playButtonClickSound(SoundManager soundManager)
    • getWidth

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

      public void setWidth(int width)
    • setHeight

      public void setHeight(int height)
    • setAlpha

      public void setAlpha(float alpha)
    • getAlpha

      public float getAlpha()
    • setMessage

      public void setMessage(Component message)
    • 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 focused)
      Description copied from interface: GuiEventListener
      Sets the focus state of the GUI element.
      Specified by:
      setFocused in interface GuiEventListener
      Parameters:
      focused - 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 output)
      Description copied from interface: NarrationSupplier
      Updates the narration output with the current narration information.
      Specified by:
      updateNarration in interface NarrationSupplier
      Parameters:
      output - the output to update with narration information.
    • updateWidgetNarration

      protected abstract void updateWidgetNarration(NarrationElementOutput output)
    • defaultButtonNarrationText

      protected void defaultButtonNarrationText(NarrationElementOutput output)
    • getX

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

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

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

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

      public int getRight()
    • getBottom

      public int getBottom()
    • visitWidgets

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

      public void setSize(int width, int height)
    • getRectangle

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

      private boolean areCoordinatesInRectangle(double x, double y)
    • setRectangle

      public void setRectangle(int width, int height, int x, int y)
    • getTabOrderGroup

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

      public void setTabOrderGroup(int tabOrderGroup)