Interface IConfigValuePopup<T>

Type Parameters:
T - the config value type selected by this popup

public interface IConfigValuePopup<T>
Popup content opened by a custom config value editor.

The config GUI places the popup near the editor control and keeps it inside the visible config area. Implementations only need to provide their preferred size and handle drawing and hit testing inside the provided popup bounds.

Since:
0.1.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    A preferred popup size.
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    charTyped(char codePoint, int modifiers, Consumer<T> valueConsumer)
    Handle a typed character while this popup has an active text field.
    default boolean
    Whether the popup should close after it selects a value.
    void
    draw(net.minecraft.client.gui.GuiGraphicsExtractor guiGraphics, net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY)
    Draw the popup.
    default Optional<T>
    getClickedValue(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, int button)
    Get the value selected by a mouse click, or Optional.empty() when the click did not select a value.
    default Optional<T>
    getDraggedValue(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, int button)
    Get the value selected while dragging the mouse, or Optional.empty() when this popup does not handle dragging.
    int
    The preferred popup height.
    getHoveredValue(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY)
    Get the value currently under the mouse, or Optional.empty() when hovering no value.
    getPreferredSize(int availableWidth, int availableHeight)
    Negotiate the preferred popup size for the currently available area.
    int
    The preferred popup width.
    default boolean
    keyPressed(int keyCode, int scanCode, int modifiers, Consumer<T> valueConsumer)
    Handle a key press while this popup has an active text field.
    default void
    mouseReleased(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, int button)
    Called after a mouse button is released over an active popup, including after a handled drag.
    default boolean
    mouseScrolled(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, double scrollX, double scrollY)
    Handle mouse-wheel input over this popup.
    default void
    Called when this popup is closed or replaced.
    default void
    Called after this popup becomes active.
  • Method Details

    • getWidth

      int getWidth()
      The preferred popup width.
      Returns:
      the preferred popup width
      Since:
      0.1.0
    • getHeight

      int getHeight()
      The preferred popup height.
      Returns:
      the preferred popup height
      Since:
      0.1.0
    • getPreferredSize

      default IConfigValuePopup.Size getPreferredSize(int availableWidth, int availableHeight)
      Negotiate the preferred popup size for the currently available area.

      The default preserves fixed-size popup behavior. Responsive implementations can return a smaller layout when the preferred fixed size does not fit.

      Parameters:
      availableWidth - available width inside the visible config area
      availableHeight - available height inside the visible config area
      Returns:
      the preferred popup size for the available area
      Since:
      0.1.0
    • getHoveredValue

      Optional<T> getHoveredValue(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY)
      Get the value currently under the mouse, or Optional.empty() when hovering no value.
      Parameters:
      area - the popup bounds
      mouseX - the current mouse x-coordinate
      mouseY - the current mouse y-coordinate
      Returns:
      the hovered value
      Since:
      0.1.0
    • draw

      void draw(net.minecraft.client.gui.GuiGraphicsExtractor guiGraphics, net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY)
      Draw the popup.
      Parameters:
      guiGraphics - the draw context
      area - the popup bounds
      mouseX - the current mouse x-coordinate
      mouseY - the current mouse y-coordinate
      Since:
      0.1.0
    • getClickedValue

      default Optional<T> getClickedValue(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, int button)
      Get the value selected by a mouse click, or Optional.empty() when the click did not select a value.

      By default, a left-click selects the hovered value.

      Parameters:
      area - the popup bounds
      mouseX - the click x-coordinate
      mouseY - the click y-coordinate
      button - the clicked mouse button
      Returns:
      the clicked value
      Since:
      0.1.0
    • getDraggedValue

      default Optional<T> getDraggedValue(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, int button)
      Get the value selected while dragging the mouse, or Optional.empty() when this popup does not handle dragging.
      Parameters:
      area - the popup bounds
      mouseX - the current mouse x-coordinate
      mouseY - the current mouse y-coordinate
      button - the held mouse button
      Returns:
      the value selected by the drag
      Since:
      0.1.0
    • mouseScrolled

      default boolean mouseScrolled(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, double scrollX, double scrollY)
      Handle mouse-wheel input over this popup.
      Parameters:
      area - the popup bounds
      mouseX - the current mouse x-coordinate
      mouseY - the current mouse y-coordinate
      scrollX - horizontal scroll amount
      scrollY - vertical scroll amount
      Returns:
      true when the popup handled the scroll
      Since:
      0.1.0
    • mouseReleased

      default void mouseReleased(net.minecraft.client.renderer.Rect2i area, double mouseX, double mouseY, int button)
      Called after a mouse button is released over an active popup, including after a handled drag.

      Click selection is routed through getClickedValue(Rect2i, double, double, int) separately. Releasing a handled drag does not invoke getClickedValue again.

      Parameters:
      area - the popup bounds
      mouseX - the release x-coordinate
      mouseY - the release y-coordinate
      button - the released mouse button
      Since:
      0.1.0
    • onOpened

      default void onOpened()
      Called after this popup becomes active.
      Since:
      0.1.0
    • onClosed

      default void onClosed()
      Called when this popup is closed or replaced.
      Since:
      0.1.0
    • charTyped

      default boolean charTyped(char codePoint, int modifiers, Consumer<T> valueConsumer)
      Handle a typed character while this popup has an active text field.
      Parameters:
      codePoint - the typed character
      modifiers - the active keyboard modifiers
      valueConsumer - receives a new value when the edit becomes valid
      Returns:
      true when the popup handled the character
      Since:
      0.1.0
    • keyPressed

      default boolean keyPressed(int keyCode, int scanCode, int modifiers, Consumer<T> valueConsumer)
      Handle a key press while this popup has an active text field.
      Parameters:
      keyCode - the key code
      scanCode - the platform scan code
      modifiers - the active keyboard modifiers
      valueConsumer - receives a new value when the edit becomes valid
      Returns:
      true when the popup handled the key press
      Since:
      0.1.0
    • closesAfterValueSelected

      default boolean closesAfterValueSelected()
      Whether the popup should close after it selects a value.

      Return false for interactive controls such as color pickers that support several adjustments before the user clicks outside the popup.

      Returns:
      true to close after selecting a value
      Since:
      0.1.0