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
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractWidget
AbstractWidget.WithInactiveMessageNested classes/interfaces inherited from interface NarratableEntry
NarratableEntry.NarrationPriority -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprivate booleanprivate booleanif true the textbox can lose focus by clicking elsewhere on the screenprivate booleanprivate static final Stringprivate static final intprivate static final intprivate intstatic final Stylestatic 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 final List<EditBox.TextFormatter> static final intprivate intother selection position, maybe the same as the cursorprivate @Nullable Componentprivate booleanprivate booleanIf this value is true along with isFocused, keyTyped will process the keys.private intstatic final Styleprivate static final WidgetSpritesprivate @Nullable Stringprivate intprivate intprivate booleanprivate intprivate intprivate StringHas the current text being edited on the textbox.Fields inherited from class AbstractWidget
active, alpha, height, isHovered, message, packedFGColor, UNSET_FG_COLOR, visible, width -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFormatter(EditBox.TextFormatter formatter) private FormattedCharSequenceapplyFormat(String text, int offset) booleanbooleancharTyped(CharacterEvent event) protected MutableComponentvoiddeleteChars(int dir) 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 pos) private voiddeleteText(int dir, boolean wholeWord) voiddeleteWords(int dir) 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 intprivate intgetCursorPos(int dir) intintprivate intintgetScreenX(int charIndex) booleangetValue()intgetWordPosition(int dir) Gets the starting index of the word at the specified number of words away from the cursor position.private intgetWordPosition(int dir, int from) Gets the starting index of the word at a distance of the specified number of words away from the given position.private intgetWordPosition(int dir, int from, boolean stripSpaces) Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spacesvoidinsertText(String input) Adds the given text after the cursor, or replaces the currently selected text if there is a selection.booleanprivate booleanprivate booleanbooleanbooleankeyPressed(KeyEvent event) voidmoveCursor(int dir, boolean hasShiftDown) voidmoveCursorTo(int dir, boolean extendSelection) voidmoveCursorToEnd(boolean hasShiftDown) voidmoveCursorToStart(boolean hasShiftDown) voidonClick(MouseButtonEvent event, boolean doubleClick) protected voidonDrag(MouseButtonEvent event, double dx, double dy) private voidonValueChange(String value) voidplayDownSound(SoundManager soundManager) voidrenderWidget(GuiGraphics graphics, int mouseX, int mouseY, float a) private voidscrollTo(int pos) private voidselectWord(MouseButtonEvent event) voidsetBordered(boolean bordered) 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.voidsetCentered(boolean centered) voidsetCursorPosition(int pos) voidsetEditable(boolean isEditable) Sets whether this text box is enabled.voidSets a filter on the edit box that will only allow strings that pass the given predicate to be inserted.voidsetFocused(boolean focused) Sets the focus state of the GUI element.voidsetHighlightPos(int pos) Sets the position of the selection anchor (the selection anchor and the cursor position mark the edges of the selection).voidvoidsetInvertHighlightedTextColor(boolean invertHighlightedTextColor) voidsetMaxLength(int maxLength) Sets the maximum length for the text in this text box.voidsetResponder(Consumer<String> responder) voidsetSuggestion(@Nullable String suggestion) voidsetTextColor(int textColor) Sets the color to use when drawing this text box's text.voidsetTextColorUneditable(int textColorUneditable) 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 visible) Sets whether this textbox is visible.voidsetX(int x) voidsetY(int y) private voidvoidMethods inherited from class AbstractWidget
clearFGColor, defaultButtonNarrationText, getAlpha, getBottom, getFGColor, getHeight, getMessage, getRectangle, getRight, getTabOrderGroup, getWidth, getX, getY, handleCursor, isActive, isFocused, isHovered, isHoveredOrFocused, isMouseOver, isValidClickButton, mouseClicked, mouseDragged, mouseReleased, narrationPriority, nextFocusPath, onRelease, playButtonClickSound, render, renderScrollingStringOverContents, setAlpha, setFGColor, setHeight, setMessage, setRectangle, setSize, setTabOrderGroup, setTooltip, setTooltipDelay, setWidth, updateNarration, visitWidgets, wrapDefaultNarrationMessageMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GuiEventListener
getBorderForArrowNavigation, getCurrentFocusPath, keyReleased, mouseMoved, mouseScrolled, shouldTakeFocusAfterInteractionMethods inherited from interface LayoutElement
setPositionMethods inherited from interface NarratableEntry
getNarratables
-
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_APPEND_CHARACTER
- See Also:
-
DEFAULT_TEXT_COLOR
public static final int DEFAULT_TEXT_COLOR- See Also:
-
DEFAULT_HINT_STYLE
-
SEARCH_HINT_STYLE
-
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. -
centered
private boolean centered -
textShadow
private boolean textShadow -
invertHighlightedTextColor
private boolean invertHighlightedTextColor -
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
-
formatters
-
hint
-
focusedTime
private long focusedTime -
textX
private int textX -
textY
private int textY -
filter
-
-
Constructor Details
-
EditBox
-
EditBox
-
EditBox
-
-
Method Details
-
setResponder
-
addFormatter
-
createNarrationMessage
- Overrides:
createNarrationMessagein classAbstractWidget
-
setValue
Sets the text of the textbox, and moves the cursor to the end. -
getValue
-
getHighlighted
-
setX
public void setX(int x) - Specified by:
setXin interfaceLayoutElement- Overrides:
setXin classAbstractWidget
-
setY
public void setY(int y) - Specified by:
setYin interfaceLayoutElement- Overrides:
setYin classAbstractWidget
-
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 dir, boolean wholeWord) -
deleteWords
public void deleteWords(int dir) 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 dir) 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 pos) -
getWordPosition
public int getWordPosition(int dir) Gets the starting index of the word at the specified number of words away from the cursor position. -
getWordPosition
private int getWordPosition(int dir, int from) 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 dir, int from, boolean stripSpaces) Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spaces -
moveCursor
public void moveCursor(int dir, boolean hasShiftDown) -
getCursorPos
private int getCursorPos(int dir) -
moveCursorTo
public void moveCursorTo(int dir, boolean extendSelection) -
setCursorPosition
public void setCursorPosition(int pos) -
moveCursorToStart
public void moveCursorToStart(boolean hasShiftDown) -
moveCursorToEnd
public void moveCursorToEnd(boolean hasShiftDown) -
keyPressed
-
canConsumeInput
public boolean canConsumeInput() -
charTyped
-
findClickedPositionInText
-
selectWord
-
onClick
- Overrides:
onClickin classAbstractWidget
-
onDrag
- Overrides:
onDragin classAbstractWidget
-
playDownSound
- Overrides:
playDownSoundin classAbstractWidget
-
renderWidget
- Specified by:
renderWidgetin classAbstractWidget
-
applyFormat
-
updateTextPosition
private void updateTextPosition() -
setMaxLength
public void setMaxLength(int maxLength) 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 bordered) Sets whether the background and outline of this text box should be drawn. -
setTextColor
public void setTextColor(int textColor) 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 textColorUneditable) Sets the color to use for text in this text box when this text box is disabled. -
setFocused
public void setFocused(boolean focused) Description copied from interface:GuiEventListenerSets 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 isEditable) Sets whether this text box is enabled. Disabled text boxes cannot be typed in. -
isCentered
private boolean isCentered() -
setCentered
public void setCentered(boolean centered) -
setTextShadow
public void setTextShadow(boolean textShadow) -
setInvertHighlightedTextColor
public void setInvertHighlightedTextColor(boolean invertHighlightedTextColor) -
getInnerWidth
public int getInnerWidth() -
setHighlightPos
public void setHighlightPos(int pos) 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 pos) -
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 visible) Sets whether this textbox is visible. -
setSuggestion
-
getScreenX
public int getScreenX(int charIndex) -
updateWidgetNarration
- Specified by:
updateWidgetNarrationin classAbstractWidget
-
setHint
-
getTextShadow
public boolean getTextShadow()
-