Class TGuiUtils

java.lang.Object
com.thecsdev.commonmc.api.client.gui.util.TGuiUtils

@Environment(CLIENT) public final class TGuiUtils extends Object
TCDCommons API's GUI-related utility methods.
  • Method Details

    • playGuiButtonClickSound

      public static final void playGuiButtonClickSound()
      Plays a GUI button click sound using the "master" volume.
    • playGuiHoverSound

      public static final void playGuiHoverSound()
      Plays a GUI sound for when a TClickableWidget is hovered.
    • playGuiTypingSound

      public static final void playGuiTypingSound()
      Plays a GUI sound for when the user types textual input into a TSimpleTextFieldWidget. Text input typing noises.
    • getGuiRenderer

      public static final net.minecraft.client.gui.render.GuiRenderer getGuiRenderer(net.minecraft.client.Minecraft client)
      Returns the GuiRenderer that belongs to a given Minecraft.
      Parameters:
      client - The Minecraft.
    • getScreenBounds

      public static final Bounds2i getScreenBounds()
      Returns the bounding box of the game window in scaled (GUI) units.
      This represents the screen dimensions in in-game units, not actual pixels.
      API Note:
      The game screen can resize at any moment. Keep this in mind!
    • isKeyDown

      public static final boolean isKeyDown(int keyCode)
      Returns true is a given key is currently held down for the current game window.
      Parameters:
      keyCode - The GLFW key code.
    • isCtrlDown

      public static final boolean isCtrlDown()
      Returns true is either the left or right control key is currently held down for the current game window.
      See Also:
    • isShiftDown

      public static final boolean isShiftDown()
      Returns true is either the left or right shift key is currently held down for the current game window.
      See Also:
    • calcMaxLineWidth

      public static final int calcMaxLineWidth(@NotNull @NotNull net.minecraft.network.chat.Component text, @NotNull @NotNull net.minecraft.client.gui.Font font) throws NullPointerException
      Calculates the maximum width a Component's line could take, assuming said Component were to be split by \n into lines.
      Parameters:
      text - The Component whose text is measured.
      font - The Font used to measure the text.
      Throws:
      NullPointerException - If an argument is null.
    • calcMaxWidth

      public static final int calcMaxWidth(@NotNull @NotNull Iterable<TElement> elements) throws NullPointerException
      Calculates the largest width among a collection of TElements.
      Parameters:
      elements - The collection of TElements.
      Throws:
      NullPointerException - If the argument is null.
    • isAncestor

      public static final boolean isAncestor(@Nullable @Nullable TElement child, @NotNull @NotNull TElement candidateAncestor) throws NullPointerException
      Checks whether a given TElement is an ancestor of another specified TElement.
      Parameters:
      child - The element whose ancestry is tested. May be null.
      candidateAncestor - The parent element to test as a possible ancestor. Must not be null.
      Returns:
      true if candidateAncestor is an ancestor of child, otherwise false.
      Throws:
      NullPointerException - if candidateAncestor is null.
    • previousFocusableTElement

      @Nullable public static final @Nullable TElement previousFocusableTElement(TElement target) throws NullPointerException
      Finds the TElement that is focusable and that comes before a given target TElement.
      Parameters:
      target - The target TElement after which to look for the previous one.
      Throws:
      NullPointerException - If an argument is null.
    • previousFocusableTElement

      @Nullable public static final @Nullable TElement previousFocusableTElement(TElement target, boolean underflow) throws NullPointerException
      Finds the TElement that is focusable and that comes before a given target TElement.
      Parameters:
      target - The target TElement after which to look for the previous one.
      underflow - When true, the search wraps around to the last focusable TElement if no elements are found before the target.
      Throws:
      NullPointerException - If an argument is null.
    • nextFocusableTElement

      @Nullable public static final @Nullable TElement nextFocusableTElement(TElement target) throws NullPointerException
      Finds the TElement that is focusable and that comes after a given target TElement.
      Parameters:
      target - The target TElement after which to look for the next one.
      Throws:
      NullPointerException - If an argument is null.
    • nextFocusableTElement

      @Nullable public static final @Nullable TElement nextFocusableTElement(TElement target, boolean overflow) throws NullPointerException
      Finds the TElement that is focusable and that comes after a given target TElement.
      Parameters:
      target - The target TElement after which to look for the next one.
      overflow - When true, the search wraps around to the first focusable TElement if no elements are found after the target.
      Throws:
      NullPointerException - If an argument is null.
    • scrollToElement

      @Contract("null -> false; _ -> _") public static final boolean scrollToElement(@Nullable @Nullable TElement target)
      Scrolls the GUI so that a given TElement is fully visible on-screen. This involves scrolling TPanelElements the TElement is part of.
      If the element is already fully visible, no scrolling occurs.
      Parameters:
      target - The target TElement to scroll to.
      Returns:
      true if scrolling was possible and done, otherwise false.
    • keepElementWithinBounds

      public static final void keepElementWithinBounds(@NotNull @NotNull TElement target, @NotNull @NotNull Bounds2i bounds) throws NullPointerException
      Ensures that a given TElement remains within specified bounds. If the element is out of bounds, it is moved back within the bounds.
      Parameters:
      target - The target TElement to keep within bounds.
      bounds - The bounding box within which the element must remain.
      Throws:
      NullPointerException - If an argument is null.