Class EditBox
java.lang.Object
net.minecraft.client.gui.components.AbstractWidget
net.minecraft.client.gui.components.EditBox
- All Implemented Interfaces:
GuiEventListener,Renderable,TabOrderedElement,LayoutElement,NarratableEntry,NarrationSupplier,IAbstractWidgetExtension
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.client.gui.narration.NarratableEntry
NarratableEntry.NarrationPriority -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprivate booleanprivate booleanif true the textbox can lose focus by clicking elsewhere on the screenprivate static final Stringprivate static final intprivate static final intprivate static final intprivate intstatic final intprivate intThe current character index that should be used as start of the rendered text.Called to check if the text is validprivate longprivate final Fontprivate BiFunction<String, Integer, FormattedCharSequence> static final intprivate intother selection position, maybe the same as the cursorprivate Componentprivate booleanIf this value is true along with isFocused, keyTyped will process the keys.private intprivate static final WidgetSpritesprivate Stringprivate intprivate intprivate booleanprivate StringHas the current text being edited on the textbox.Fields inherited from class net.minecraft.client.gui.components.AbstractWidget
active, alpha, height, isHovered, packedFGColor, UNSET_FG_COLOR, visible, widthFields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
DOUBLE_CLICK_THRESHOLD_MS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleancharTyped(char codePoint, int modifiers) Called when a character is typed within the GUI element.protected MutableComponentvoiddeleteChars(int num) Deletes the given number of characters from the current cursor's position, unless there is currently a selection, in which case the selection is deleted instead.voiddeleteCharsToPos(int num) private voiddeleteText(int count) voiddeleteWords(int num) Deletes the given number of words from the current cursor's position, unless there is currently a selection, in which case the selection is deleted instead.private intgetCursorPos(int delta) intintprivate intintgetScreenX(int charNum) booleangetValue()intgetWordPosition(int numWords) Gets the starting index of the word at the specified number of words away from the cursor position.private intgetWordPosition(int numWords, int pos) Gets the starting index of the word at a distance of the specified number of words away from the given position.private intgetWordPosition(int numWords, int pos, boolean skipConsecutiveSpaces) Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spacesvoidinsertText(String textToWrite) Adds the given text after the cursor, or replaces the currently selected text if there is a selection.booleanprivate booleanbooleanbooleankeyPressed(int keyCode, int scanCode, int modifiers) Called when a keyboard key is pressed within the GUI element.voidmoveCursor(int delta, boolean select) voidmoveCursorTo(int delta, boolean select) voidmoveCursorToEnd(boolean select) voidmoveCursorToStart(boolean select) voidonClick(double mouseX, double mouseY) private voidonValueChange(String newText) voidplayDownSound(SoundManager handler) private voidrenderHighlight(GuiGraphics guiGraphics, int minX, int minY, int maxX, int maxY) voidrenderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) private voidscrollTo(int position) voidsetBordered(boolean enableBackgroundDrawing) Sets whether the background and outline of this text box should be drawn.voidsetCanLoseFocus(boolean canLoseFocus) Sets whether this text box loses focus when something other than it is clicked.voidsetCursorPosition(int pos) voidsetEditable(boolean enabled) Sets whether this text box is enabled.voidvoidsetFocused(boolean focused) Sets the focus state of the GUI element.voidsetFormatter(BiFunction<String, Integer, FormattedCharSequence> textFormatter) voidsetHighlightPos(int position) Sets the position of the selection anchor (the selection anchor and the cursor position mark the edges of the selection).voidvoidsetMaxLength(int length) Sets the maximum length for the text in this text box.voidsetResponder(Consumer<String> responder) voidsetSuggestion(String suggestion) voidsetTextColor(int color) Sets the color to use when drawing this text box's text.voidsetTextColorUneditable(int color) Sets the color to use for text in this text box when this text box is disabled.voidsetTextShadow(boolean textShadow) voidSets the text of the textbox, and moves the cursor to the end.voidsetVisible(boolean isVisible) Sets whether this textbox is visible.voidupdateWidgetNarration(NarrationElementOutput narrationElementOutput) Methods inherited from class net.minecraft.client.gui.components.AbstractWidget
clearFGColor, clicked, defaultButtonNarrationText, getBottom, getFGColor, getHeight, getMessage, getRectangle, getRight, getTabOrderGroup, getTooltip, getWidth, getX, getY, isActive, isFocused, isHovered, isHoveredOrFocused, isMouseOver, isValidClickButton, mouseClicked, mouseDragged, mouseReleased, narrationPriority, nextFocusPath, onDrag, onRelease, render, renderScrollingString, renderScrollingString, renderScrollingString, setAlpha, setFGColor, setHeight, setMessage, setRectangle, setSize, setTabOrderGroup, setTooltip, setTooltipDelay, setWidth, setX, setY, updateNarration, visitWidgets, wrapDefaultNarrationMessageMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
getCurrentFocusPath, keyReleased, mouseMoved, mouseScrolledMethods inherited from interface net.neoforged.neoforge.client.extensions.IAbstractWidgetExtension
onClickMethods inherited from interface net.minecraft.client.gui.layouts.LayoutElement
setPositionMethods inherited from interface net.minecraft.client.gui.components.Renderable
render
-
Field Details
-
SPRITES
-
BACKWARDS
public static final int BACKWARDS- See Also:
-
FORWARDS
public static final int FORWARDS- See Also:
-
CURSOR_INSERT_WIDTH
private static final int CURSOR_INSERT_WIDTH- See Also:
-
CURSOR_INSERT_COLOR
private static final int CURSOR_INSERT_COLOR- See Also:
-
CURSOR_APPEND_CHARACTER
- See Also:
-
DEFAULT_TEXT_COLOR
public static final int DEFAULT_TEXT_COLOR- See Also:
-
CURSOR_BLINK_INTERVAL_MS
private static final int CURSOR_BLINK_INTERVAL_MS- See Also:
-
font
-
value
Has the current text being edited on the textbox. -
maxLength
private int maxLength -
bordered
private boolean bordered -
canLoseFocus
private boolean canLoseFocusif true the textbox can lose focus by clicking elsewhere on the screen -
isEditable
private boolean isEditableIf this value is true along with isFocused, keyTyped will process the keys. -
displayPos
private int displayPosThe current character index that should be used as start of the rendered text. -
cursorPos
private int cursorPos -
highlightPos
private int highlightPosother selection position, maybe the same as the cursor -
textColor
private int textColor -
textColorUneditable
private int textColorUneditable -
suggestion
-
responder
-
filter
Called to check if the text is valid -
formatter
-
hint
-
focusedTime
private long focusedTime -
textShadow
private boolean textShadow
-
-
Constructor Details
-
EditBox
-
EditBox
-
EditBox
-
-
Method Details
-
setResponder
-
setFormatter
-
createNarrationMessage
- Overrides:
createNarrationMessagein classAbstractWidget
-
setValue
Sets the text of the textbox, and moves the cursor to the end. -
getValue
-
getHighlighted
-
setFilter
-
insertText
Adds the given text after the cursor, or replaces the currently selected text if there is a selection. -
onValueChange
-
deleteText
private void deleteText(int count) -
deleteWords
public void deleteWords(int num) Deletes the given number of words from the current cursor's position, unless there is currently a selection, in which case the selection is deleted instead. -
deleteChars
public void deleteChars(int num) Deletes the given number of characters from the current cursor's position, unless there is currently a selection, in which case the selection is deleted instead. -
deleteCharsToPos
public void deleteCharsToPos(int num) -
getWordPosition
public int getWordPosition(int numWords) Gets the starting index of the word at the specified number of words away from the cursor position. -
getWordPosition
private int getWordPosition(int numWords, int pos) Gets the starting index of the word at a distance of the specified number of words away from the given position. -
getWordPosition
private int getWordPosition(int numWords, int pos, boolean skipConsecutiveSpaces) Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spaces -
moveCursor
public void moveCursor(int delta, boolean select) -
getCursorPos
private int getCursorPos(int delta) -
moveCursorTo
public void moveCursorTo(int delta, boolean select) -
setCursorPosition
public void setCursorPosition(int pos) -
moveCursorToStart
public void moveCursorToStart(boolean select) -
moveCursorToEnd
public void moveCursorToEnd(boolean select) -
keyPressed
public boolean keyPressed(int keyCode, int scanCode, int modifiers) Called when a keyboard key is pressed within the GUI element.- Specified by:
keyPressedin interfaceGuiEventListener- Parameters:
keyCode- the key code of the pressed key.scanCode- the scan code of the pressed key.modifiers- the keyboard modifiers.- Returns:
trueif the event is consumed,falseotherwise.
-
canConsumeInput
public boolean canConsumeInput() -
charTyped
public boolean charTyped(char codePoint, int modifiers) Called when a character is typed within the GUI element.- Specified by:
charTypedin interfaceGuiEventListener- Parameters:
codePoint- the code point of the typed character.modifiers- the keyboard modifiers.- Returns:
trueif the event is consumed,falseotherwise.
-
onClick
public void onClick(double mouseX, double mouseY) - Overrides:
onClickin classAbstractWidget
-
playDownSound
- Overrides:
playDownSoundin classAbstractWidget
-
renderWidget
- Specified by:
renderWidgetin classAbstractWidget
-
renderHighlight
-
setMaxLength
public void setMaxLength(int length) Sets the maximum length for the text in this text box. If the current text is longer than this length, the current text will be trimmed. -
getMaxLength
private int getMaxLength() -
getCursorPosition
public int getCursorPosition() -
isBordered
public boolean isBordered() -
setBordered
public void setBordered(boolean enableBackgroundDrawing) Sets whether the background and outline of this text box should be drawn. -
setTextColor
public void setTextColor(int color) Sets the color to use when drawing this text box's text. A different color is used if this text box is disabled. -
setTextColorUneditable
public void setTextColorUneditable(int color) Sets the color to use for text in this text box when this text box is disabled. -
setFocused
public void setFocused(boolean focused) Sets the focus state of the GUI element.- Specified by:
setFocusedin interfaceGuiEventListener- Overrides:
setFocusedin classAbstractWidget- Parameters:
focused-trueto apply focus,falseto remove focus
-
isEditable
private boolean isEditable() -
setEditable
public void setEditable(boolean enabled) Sets whether this text box is enabled. Disabled text boxes cannot be typed in. -
getInnerWidth
public int getInnerWidth() -
setHighlightPos
public void setHighlightPos(int position) Sets the position of the selection anchor (the selection anchor and the cursor position mark the edges of the selection). If the anchor is set beyond the bounds of the current text, it will be put back inside. -
scrollTo
private void scrollTo(int position) -
setCanLoseFocus
public void setCanLoseFocus(boolean canLoseFocus) Sets whether this text box loses focus when something other than it is clicked. -
isVisible
public boolean isVisible() -
setVisible
public void setVisible(boolean isVisible) Sets whether this textbox is visible. -
setSuggestion
-
getScreenX
public int getScreenX(int charNum) -
updateWidgetNarration
- Specified by:
updateWidgetNarrationin classAbstractWidget
-
setHint
-
setTextShadow
public void setTextShadow(boolean textShadow) -
getTextShadow
public boolean getTextShadow()
-