Class GuiTextField
java.lang.Object
codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry<GuiTextField>
codechicken.lib.gui.modular.elements.GuiElement<GuiTextField>
codechicken.lib.gui.modular.elements.GuiTextField
- All Implemented Interfaces:
BackgroundRender,ElementEvents,GuiParent<GuiTextField>,TooltipHandler<GuiTextField>
TODO, Re write this, Its currently mostly pulled from the TextField in Gui v2
Created by brandon3055 on 03/09/2023
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class codechicken.lib.gui.modular.elements.GuiElement
hoverTime, initialized -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleancharTyped(net.minecraft.client.input.CharacterEvent event) Override this method to implement handling for the charTyped event.static GuiTextField.TextFieldcreate(GuiElement<?> parent, int backgroundColour, int borderColour, int textColour) Creates a simple text box with a simple bordered background.voiddeleteChars(int i1) voiddeleteWords(int i) intgetValue()intgetWordPosition(int i) voidinsertText(String text) booleanbooleanbooleankeyPressed(net.minecraft.client.input.KeyEvent event) Override this method to implement handling for the keyPressed event.booleankeyReleased(net.minecraft.client.input.KeyEvent event, boolean consumed) Root handler for keyReleased event.booleanmouseClicked(net.minecraft.client.input.MouseButtonEvent event, boolean consumed) Root handler for mouseClick event.voidmoveCursor(int pos) voidmoveCursorTo(int pos) voidmoveCursorTo(int pos, boolean notify) voidvoidmoveCursorToEnd(boolean notify) voidvoidrenderBehind(net.minecraft.client.gui.GuiGraphics render, double mouseX, double mouseY, float partialTicks) Used to render content behind this elements child elements.setCanLoseFocus(boolean canLoseFocus) If set to false, it will not be possible for the text field to lose focus via normal means.setCanLoseFocus(Supplier<Boolean> canLoseFocus) If set to false, it will not be possible for the text field to lose focus via normal means.voidsetCursorPosition(int pos) setEditable(boolean editable) If false, It will not be possible for the user to edit the value of this text field.setEditable(Supplier<Boolean> editable) If false, It will not be possible for the user to edit the value of this text field.setEnterPressed(Runnable onEnterPressed) Called when the user presses enter key (Including numpad enter) with the text box ion focusAllows you to apply a fielder to this text field.voidsetFocus(boolean focused) setFocusable(boolean focusable) If false, It will not be possible to focus this element by clicking on it.setFocusable(Supplier<Boolean> focusable) If false, It will not be possible to focus this element by clicking on it.setFormatter(BiFunction<String, Integer, net.minecraft.util.FormattedCharSequence> formatter) Formats the current text value for display to the user.voidsetHighlightPos(int newPos) setMaxLength(int newWidth) Sets the maximum allowed text lengthsetOnEditComplete(Runnable onEditComplete) Called when the user clicks outside the text box, or when they press entersetShadow(boolean shadow) Should the text be rendered with a shadow?Should the text be rendered with a shadow?setSuggestion(@Nullable Supplier<net.minecraft.network.chat.Component> suggestion) Set the "suggestion" text that is displayed when the text field is empty.setSuggestion(net.minecraft.network.chat.Component suggestion) Set the "suggestion" text that is displayed when the text field is empty.setSuggestionColour(int suggestionColour) setSuggestionColour(Supplier<Integer> suggestionColour) Set the colour of the suggestion text.setSuggestionShadow(boolean suggestionShadow) setSuggestionShadow(Supplier<Boolean> suggestionShadow) setTextColor(int textColor) setTextColor(Supplier<Integer> textColor) setTextState(TextState textState) TheTextStateis an accessor for the current text value.Note, Initial value should be set after element is constrained, If element width is zero when set, nothing will render until the field is updated.voidtick(double mouseX, double mouseY) Called every tick to update the element.Methods inherited from class codechicken.lib.gui.modular.elements.GuiElement
addChild, addJeiDropTargets, addJeiExclusions, adoptChild, applyQueuedChildUpdates, blockMouseEvents, blockMouseOver, bringChildToForeground, font, getChildren, getJeiDropConsumer, getModularGui, getParent, getTooltip, getTooltipDelay, hoverTime, initElement, isDescendantOf, isEnabled, isJeiDropTarget, isJeiExcluded, isMouseOver, isOpaque, isRemoved, isTooltipEnabled, jeiExclude, mc, onScreenInit, removeChild, render, renderChild, renderOverlay, scaledScreenHeight, scaledScreenWidth, sendChildToBackground, sendChildToIndex, setEnabled, setEnabled, setEnableToolTip, setJeiDropTarget, setJeiExcluded, setOpaque, setRenderCull, setTooltip, setTooltipDelay, showToolTip, toString, updateMouseOver, updateScreenDataMethods inherited from class codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry
addBoundsToRect, clearConstraints, clearGeometryCache, constrain, get, getChildBounds, getEnclosingRect, getParent, getPosition, getRectangle, placeInside, placeInside, placeOutside, placeOutside, setHeight, setPos, setSize, setWidth, setXPos, setYPos, strictMode, validate, xCenter, xMax, xMin, xSize, yCenter, yMax, yMin, ySizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface codechicken.lib.gui.modular.lib.ElementEvents
charTyped, keyPressed, keyReleased, mouseClicked, mouseMoved, mouseReleased, mouseReleased, mouseScrolled, mouseScrolledMethods inherited from interface codechicken.lib.gui.modular.lib.geometry.GuiParent
addChild, getValueMethods inherited from interface codechicken.lib.gui.modular.lib.TooltipHandler
renderTooltip, setTooltip, setTooltip, setTooltip, setTooltipSingle, setTooltipSingle
-
Constructor Details
-
GuiTextField
-
-
Method Details
-
create
public static GuiTextField.TextField create(GuiElement<?> parent, int backgroundColour, int borderColour, int textColour) Creates a simple text box with a simple bordered background. Using colours 0xFF000000, 0xFFFFFFFF, 0xE0E0E0 will get you a text box identical to the one in a command block -
setOnEditComplete
Called when the user clicks outside the text box, or when they press enter -
setEnterPressed
Called when the user presses enter key (Including numpad enter) with the text box ion focus -
setTextState
TheTextStateis an accessor for the current text value. It simply contains string getter and setter methods. You can use this to link the text field to some external value. -
getTextState
-
setTextColor
-
setTextColor
-
setShadow
Should the text be rendered with a shadow? -
setShadow
Should the text be rendered with a shadow? -
setSuggestion
Set the "suggestion" text that is displayed when the text field is empty. -
setSuggestion
public GuiTextField setSuggestion(@Nullable @Nullable Supplier<net.minecraft.network.chat.Component> suggestion) Set the "suggestion" text that is displayed when the text field is empty. -
setSuggestionColour
Set the colour of the suggestion text. -
setSuggestionColour
-
setSuggestionShadow
-
setSuggestionShadow
-
setFilter
Allows you to apply a fielder to this text field. Whenever this field's value is updated, If the new value does not pass this filter It will not be applied. -
setFormatter
public GuiTextField setFormatter(BiFunction<String, Integer, net.minecraft.util.FormattedCharSequence> formatter) Formats the current text value for display to the user. The integer is the current display start position within the current field value. -
setCanLoseFocus
If set to false, it will not be possible for the text field to lose focus via normal means. Focus can still be set viasetFocus(boolean) -
setCanLoseFocus
If set to false, it will not be possible for the text field to lose focus via normal means. Focus can still be set viasetFocus(boolean) -
setFocusable
If false, It will not be possible to focus this element by clicking on it. -
setFocusable
If false, It will not be possible to focus this element by clicking on it. -
setEditable
If false, It will not be possible for the user to edit the value of this text field. -
setEditable
If false, It will not be possible for the user to edit the value of this text field. -
setMaxLength
Sets the maximum allowed text length -
setValue
Note, Initial value should be set after element is constrained, If element width is zero when set, nothing will render until the field is updated. TODO, I need to fix this. Element size should be able to change dynamically without things breaking. -
getValue
-
getHighlighted
-
insertText
-
deleteWords
public void deleteWords(int i) -
deleteChars
public void deleteChars(int i1) -
getWordPosition
public int getWordPosition(int i) -
moveCursor
public void moveCursor(int pos) -
moveCursorTo
public void moveCursorTo(int pos, boolean notify) -
moveCursorTo
public void moveCursorTo(int pos) -
setCursorPosition
public void setCursorPosition(int pos) -
moveCursorToStart
public void moveCursorToStart() -
moveCursorToEnd
public void moveCursorToEnd(boolean notify) -
moveCursorToEnd
public void moveCursorToEnd() -
isEditable
public boolean isEditable() -
setFocus
public void setFocus(boolean focused) -
isFocused
public boolean isFocused() -
getCursorPosition
public int getCursorPosition() -
setHighlightPos
public void setHighlightPos(int newPos) -
keyPressed
public boolean keyPressed(net.minecraft.client.input.KeyEvent event) Description copied from interface:ElementEventsOverride this method to implement handling for the keyPressed event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can overrideElementEvents.keyPressed(KeyEvent, boolean)Note: You do not need to call super when overriding this interface method.
- Specified by:
keyPressedin interfaceElementEvents- Parameters:
event- The key event. Key, scancode, and modifiers.- Returns:
- true to consume event.
-
canConsumeInput
public boolean canConsumeInput() -
keyReleased
public boolean keyReleased(net.minecraft.client.input.KeyEvent event, boolean consumed) Description copied from interface:ElementEventsRoot handler for keyReleased 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 keyReleased handling should be implemented viaElementEvents.keyReleased(KeyEvent)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:
keyReleasedin interfaceElementEvents- Parameters:
event- The key event. Key, scancode, and modifiers.consumed- Will be true if this action has already been consumed.- Returns:
- true if this event has been consumed.
-
charTyped
public boolean charTyped(net.minecraft.client.input.CharacterEvent event) Description copied from interface:ElementEventsOverride this method to implement handling for the charTyped event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can overrideElementEvents.charTyped(CharacterEvent, boolean)Note: You do not need to call super when overriding this interface method.
- Specified by:
charTypedin interfaceElementEvents- Parameters:
event- The character event, codepoint and modifiers.- Returns:
- true to consume event.
-
mouseClicked
public boolean mouseClicked(net.minecraft.client.input.MouseButtonEvent event, boolean consumed) Description copied from interface:ElementEventsRoot handler for mouseClick 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 mouseClick handling should be implemented viaElementEvents.mouseClicked(MouseButtonEvent)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:
mouseClickedin interfaceElementEvents- Parameters:
event- The mouse button event. Position, Key, and modifiers.consumed- Will be true if this action has already been consumed.- Returns:
- true if this event has been consumed.
-
renderBehind
public void renderBehind(net.minecraft.client.gui.GuiGraphics render, double mouseX, double mouseY, float partialTicks) Description copied from interface:BackgroundRenderUsed to render content behind this elements child elements. When rendering element content, always use thePoseStackavailable via the providedWhere applicable, always use push/pop to ensure the stack is returned to its original state after your rendering is complete.invalid reference
GuiRender- Specified by:
renderBehindin interfaceBackgroundRender- Parameters:
render- Contains gui context information as well as essential render methods/utils including the PoseStack.
-
tick
public void tick(double mouseX, double mouseY) Description copied from class:GuiElementCalled every tick to update the element. Note this is called regardless of weather or not the element is actually enabled.- Overrides:
tickin classGuiElement<GuiTextField>- Parameters:
mouseX- Current mouse X positionmouseY- Current mouse Y position
-