Class GuiManipulable

All Implemented Interfaces:
ContentElement<GuiElement<?>>, ElementEvents, GuiParent<GuiManipulable>, TooltipHandler<GuiManipulable>
Direct Known Subclasses:
GuiColourPicker

public class GuiManipulable extends GuiElement<GuiManipulable> implements ContentElement<GuiElement<?>>
This element can be used to create movable/resizable guis of gui elements. This is achieved via a "contentElement" to which all child elements should eb attached. Initially the bounds of the content element will match the parent GuiManipulable element. However, depending on which features are enabled, it is possible for the user to resize the content element by clicking and dragging the edges, or move the element by clicking and dragging a specified "dragArea".

It should be noted that the constraints on the underlying GuiManipulable should be fairly rigid. Things like dynamic constraint changes will not translate through to the contentElement,

If a UI resize occurs the content element's bounds will be reset to default. You can also trigger a manual reset by calling resetBounds()

Created by brandon3055 on 13/11/2023

  • Field Details

  • Constructor Details

    • GuiManipulable

      public GuiManipulable(@NotNull @NotNull GuiParent<?> parent)
  • Method Details

    • resetBounds

      public GuiManipulable resetBounds()
    • constrain

      public GuiManipulable constrain(GeoParam param, @Nullable @Nullable Constraint constraint)
      Overrides:
      constrain in class ConstrainedGeometry<GuiManipulable>
      Parameters:
      param - The geometry parameter to be constrained.
      constraint - The constraint to apply
      Returns:
      This Element.
    • onScreenInit

      public void onScreenInit(net.minecraft.client.Minecraft mc, net.minecraft.client.gui.Font font, int screenWidth, int screenHeight)
      Description copied from interface: GuiParent
      Called when the minecraft Screen is initialised or resized.
      Specified by:
      onScreenInit in interface GuiParent<GuiManipulable>
      Overrides:
      onScreenInit in class GuiElement<GuiManipulable>
      Parameters:
      mc - The Minecraft instance.
      font - The active font.
      screenWidth - The current guiScaledWidth.
      screenHeight - The current guiScaledHeight.
    • setResetOnUiInit

      public GuiManipulable setResetOnUiInit(boolean resetOnUiInit)
      Parameters:
      resetOnUiInit - If true, element bounds will be reset on UI init. (Default: true)
    • getContentElement

      public GuiElement<?> getContentElement()
      Specified by:
      getContentElement in interface ContentElement<GuiElement<?>>
    • addResizeHandles

      public GuiManipulable addResizeHandles(int handleSize, boolean includeTopHandle)
    • addTopHandle

      public GuiManipulable addTopHandle(int handleSize)
    • setTopHandle

      public GuiManipulable setTopHandle(GuiElement<?> topHandle)
    • addBottomHandle

      public GuiManipulable addBottomHandle(int handleSize)
    • setBottomHandle

      public GuiManipulable setBottomHandle(GuiElement<?> bottomHandle)
    • addLeftHandle

      public GuiManipulable addLeftHandle(int handleSize)
    • setLeftHandle

      public GuiManipulable setLeftHandle(GuiElement<?> leftHandle)
    • addRightHandle

      public GuiManipulable addRightHandle(int handleSize)
    • setRightHandle

      public GuiManipulable setRightHandle(GuiElement<?> rightHandle)
    • addMoveHandle

      public GuiManipulable addMoveHandle(int handleSize)
    • setMoveHandle

      public GuiManipulable setMoveHandle(GuiElement<?> moveHandle)
    • getMoveHandle

      public GuiElement<?> getMoveHandle()
      You can use this to retrieve the current move handle. You are free to update the constraints on this handle, but it must be constrained relative to the content element.
    • getLeftHandle

      public GuiElement<?> getLeftHandle()
      You can use this to retrieve the current left resize handle. You are free to update the constraints on this handle, but it must be constrained relative to the content element.
    • getRightHandle

      public GuiElement<?> getRightHandle()
      You can use this to retrieve the current right resize handle. You are free to update the constraints on this handle, but it must be constrained relative to the content element.
    • getTopHandle

      public GuiElement<?> getTopHandle()
      You can use this to retrieve the current top resize handle. You are free to update the constraints on this handle, but it must be constrained relative to the content element.
    • getBottomHandle

      public GuiElement<?> getBottomHandle()
      You can use this to retrieve the current bottom resize handle. You are free to update the constraints on this handle, but it must be constrained relative to the content element.
    • enableCursors

      public GuiManipulable enableCursors(boolean enableCursors)
      Enables rendering of custom mouse cursors when hovering over a draggable handle.
    • setOnMovedCallback

      public GuiManipulable setOnMovedCallback(Runnable onMovedCallback)
    • setOnMovedCallback

      public GuiManipulable setOnMovedCallback(Consumer<Boolean> onMovedCallback)
    • setOnResizedCallback

      public GuiManipulable setOnResizedCallback(Runnable onResizedCallback)
    • setOnResizedCallback

      public GuiManipulable setOnResizedCallback(Consumer<Boolean> onResizedCallback)
    • setPositionRestraint

      public GuiManipulable setPositionRestraint(GuiManipulable.PositionRestraint positionRestraint)
    • setMinSize

      public void setMinSize(Rectangle minSize)
    • setMaxSize

      public void setMaxSize(Rectangle maxSize)
    • getMinSize

      public Rectangle getMinSize()
    • getMaxSize

      public Rectangle getMaxSize()
    • tick

      public void tick(double mouseX, double mouseY)
      Description copied from class: GuiElement
      Called every tick to update the element. Note this is called regardless of weather or not the element is actually enabled.
      Overrides:
      tick in class GuiElement<GuiManipulable>
      Parameters:
      mouseX - Current mouse X position
      mouseY - Current mouse Y position
    • startDragging

      public void startDragging()
    • mouseMoved

      public void mouseMoved(double mouseX, double mouseY)
      Description copied from interface: ElementEvents
      Called whenever the cursor position changes. Vanillas mouseDragged is not passed through because it is redundant. All mouse drag functionality can be archived using available events.
      Specified by:
      mouseMoved in interface ElementEvents
      Parameters:
      mouseX - new mouse X position
      mouseY - new mouse Y position
    • mouseReleased

      public boolean mouseReleased(double mouseX, double mouseY, int button, boolean consumed)
      Description copied from interface: ElementEvents
      Root 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 via ElementEvents.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.

      Specified by:
      mouseReleased in interface ElementEvents
      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • validatePosition

      protected void validatePosition(boolean finished)
    • onMoved

      protected void onMoved(boolean finished)
    • onResized

      protected void onResized(boolean finished)
    • isMoving

      public boolean isMoving()
    • isResizing

      public boolean isResizing()