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(char charTyped, int charCode) 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) doubleSpecifies the z depth of the background content.intgetValue()intgetWordPosition(int i) voidinsertText(String text) booleanbooleanbooleankeyPressed(int key, int scancode, int modifiers) Override this method to implement handling for the keyPressed event.booleankeyReleased(int key, int scancode, int modifiers, boolean consumed) Root handler for keyReleased event.booleanmouseClicked(double mouseX, double mouseY, int button, boolean consumed) Root handler for mouseClick event.voidmoveCursor(int pos) voidmoveCursorTo(int pos) voidmoveCursorTo(int pos, boolean notify) voidvoidmoveCursorToEnd(boolean notify) voidvoidrenderBackground(GuiRender 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, getCombinedElementDepth, 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, setZStacking, showToolTip, toString, updateMouseOver, updateScreenData, zStackingMethods 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(int key, int scancode, int modifiers) 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(int, int, int, boolean)Note: You do not need to call super when overriding this interface method.
- Specified by:
keyPressedin interfaceElementEvents- Parameters:
key- the keyboard key that was pressed.scancode- the system-specific scancode of the keymodifiers- bitfield describing which modifier keys were held down.- Returns:
- true to consume event.
-
canConsumeInput
public boolean canConsumeInput() -
keyReleased
public boolean keyReleased(int key, int scancode, int modifiers, 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(int, int, 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:
keyReleasedin interfaceElementEvents- Parameters:
key- the keyboard key that was released.scancode- the system-specific scancode of the keymodifiers- bitfield describing which modifier keys were held down.consumed- Will be true if this action has already been consumed.- Returns:
- true if this event has been consumed.
-
charTyped
public boolean charTyped(char charTyped, int charCode) 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(char, int, boolean)Note: You do not need to call super when overriding this interface method.
- Specified by:
charTypedin interfaceElementEvents- Parameters:
charTyped- The character typed.charCode- bitfield describing which modifier keys were held down.- Returns:
- true to consume event.
-
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button, 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(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:
mouseClickedin interfaceElementEvents- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionbutton- Mouse Buttonconsumed- Will be true if this action has already been consumed.- Returns:
- true if this event has been consumed.
-
getBackgroundDepth
public double getBackgroundDepth()Description copied from interface:BackgroundRenderSpecifies the z depth of the background content. AfterBackgroundRender.renderBackground(GuiRender, double, double, float)is called, the PoseStack will be translated by this amount in the z direction before any assigned child elements are rendered. Recommended minimum depth is 0.01 or 0.035 if this element renders text. (text shadows are rendered with a 0.03 offset)- Specified by:
getBackgroundDepthin interfaceBackgroundRender- Returns:
- the z height of the background content.
-
renderBackground
Description copied from interface:BackgroundRenderUsed to render content behind this elements child elements. When rendering element content, always use thePoseStackavailable via the providedGuiRenderWhere applicable, always use push/pop to ensure the stack is returned to its original state after your rendering is complete.- Specified by:
renderBackgroundin 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
-