Class TGuiUtils
java.lang.Object
com.thecsdev.commonmc.api.client.gui.util.TGuiUtils
TCDCommons API's GUI-related utility methods.-
Method Summary
Modifier and TypeMethodDescriptionstatic final intcalcMaxLineWidth(@NotNull net.minecraft.network.chat.Component text, @NotNull net.minecraft.client.gui.Font font) Calculates the maximum width aComponent's line could take, assuming saidComponentwere to be split by\ninto lines.static final intcalcMaxWidth(@NotNull Iterable<TElement> elements) Calculates the largest width among a collection ofTElements.static final net.minecraft.client.gui.render.GuiRenderergetGuiRenderer(net.minecraft.client.Minecraft client) Returns theGuiRendererthat belongs to a givenMinecraft.static final Bounds2iReturns the bounding box of the game window in scaled (GUI) units.
This represents the screen dimensions in in-game units, not actual pixels.static final booleanisAncestor(@Nullable TElement child, @NotNull TElement candidateAncestor) static final booleanReturnstrueis either the left or right control key is currently held down for the current game window.static final booleanisKeyDown(int keyCode) Returnstrueis a given key is currently held down for the current game window.static final booleanReturnstrueis either the left or right shift key is currently held down for the current game window.static final voidkeepElementWithinBounds(@NotNull TElement target, @NotNull Bounds2i bounds) Ensures that a givenTElementremains within specified bounds.static final @Nullable TElementnextFocusableTElement(TElement target) static final @Nullable TElementnextFocusableTElement(TElement target, boolean overflow) static final voidPlays a GUI button click sound using the "master" volume.static final voidPlays a GUI sound for when aTClickableWidgetis hovered.static final voidPlays a GUI sound for when the user types textual input into aTSimpleTextFieldWidget.static final @Nullable TElementpreviousFocusableTElement(TElement target) static final @Nullable TElementpreviousFocusableTElement(TElement target, boolean underflow) static final booleanscrollToElement(@Nullable TElement target) Scrolls the GUI so that a givenTElementis fully visible on-screen.
-
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 aTClickableWidgetis hovered. -
playGuiTypingSound
public static final void playGuiTypingSound()Plays a GUI sound for when the user types textual input into aTSimpleTextFieldWidget. Text input typing noises. -
getGuiRenderer
public static final net.minecraft.client.gui.render.GuiRenderer getGuiRenderer(net.minecraft.client.Minecraft client) Returns theGuiRendererthat belongs to a givenMinecraft.- Parameters:
client- TheMinecraft.
-
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) Returnstrueis a given key is currently held down for the current game window.- Parameters:
keyCode- TheGLFWkey code.
-
isCtrlDown
public static final boolean isCtrlDown()Returnstrueis either the left or right control key is currently held down for the current game window.- See Also:
-
isShiftDown
public static final boolean isShiftDown()Returnstrueis 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 aComponent's line could take, assuming saidComponentwere to be split by\ninto lines.- Parameters:
text- TheComponentwhose text is measured.font- TheFontused to measure the text.- Throws:
NullPointerException- If an argument isnull.
-
calcMaxWidth
public static final int calcMaxWidth(@NotNull @NotNull Iterable<TElement> elements) throws NullPointerException Calculates the largest width among a collection ofTElements.- Parameters:
elements- The collection ofTElements.- Throws:
NullPointerException- If the argument isnull.
-
isAncestor
public static final boolean isAncestor(@Nullable @Nullable TElement child, @NotNull @NotNull TElement candidateAncestor) throws NullPointerException - Parameters:
child- The element whose ancestry is tested. May benull.candidateAncestor- The parent element to test as a possible ancestor. Must not benull.- Returns:
trueifcandidateAncestoris an ancestor ofchild, otherwisefalse.- Throws:
NullPointerException- ifcandidateAncestorisnull.
-
previousFocusableTElement
@Nullable public static final @Nullable TElement previousFocusableTElement(TElement target) throws NullPointerException - Parameters:
target- The targetTElementafter which to look for the previous one.- Throws:
NullPointerException- If an argument isnull.
-
previousFocusableTElement
@Nullable public static final @Nullable TElement previousFocusableTElement(TElement target, boolean underflow) throws NullPointerException - Parameters:
target- The targetTElementafter which to look for the previous one.underflow- Whentrue, the search wraps around to the last focusableTElementif no elements are found before the target.- Throws:
NullPointerException- If an argument isnull.
-
nextFocusableTElement
@Nullable public static final @Nullable TElement nextFocusableTElement(TElement target) throws NullPointerException - Parameters:
target- The targetTElementafter which to look for the next one.- Throws:
NullPointerException- If an argument isnull.
-
nextFocusableTElement
@Nullable public static final @Nullable TElement nextFocusableTElement(TElement target, boolean overflow) throws NullPointerException - Parameters:
target- The targetTElementafter which to look for the next one.overflow- Whentrue, the search wraps around to the first focusableTElementif no elements are found after the target.- Throws:
NullPointerException- If an argument isnull.
-
scrollToElement
@Contract("null -> false; _ -> _") public static final boolean scrollToElement(@Nullable @Nullable TElement target) Scrolls the GUI so that a givenTElementis fully visible on-screen. This involves scrollingTPanelElements theTElementis part of.
If the element is already fully visible, no scrolling occurs.- Parameters:
target- The targetTElementto scroll to.- Returns:
trueif scrolling was possible and done, otherwisefalse.
-
keepElementWithinBounds
public static final void keepElementWithinBounds(@NotNull @NotNull TElement target, @NotNull @NotNull Bounds2i bounds) throws NullPointerException Ensures that a givenTElementremains within specified bounds. If the element is out of bounds, it is moved back within the bounds.- Parameters:
target- The targetTElementto keep within bounds.bounds- The bounding box within which the element must remain.- Throws:
NullPointerException- If an argument isnull.
-