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 int
private boolean
private boolean
if true the textbox can lose focus by clicking elsewhere on the screenprivate static final String
private static final int
private static final int
private static final int
private int
static final int
private int
The current character index that should be used as start of the rendered text.Called to check if the text is validprivate long
private final Font
private BiFunction
<String, Integer, FormattedCharSequence> static final int
private int
other selection position, maybe the same as the cursorprivate Component
private boolean
If this value is true along with isFocused, keyTyped will process the keys.private int
private static final WidgetSprites
private String
private int
private int
private boolean
private String
Has 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, width
Fields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
DOUBLE_CLICK_THRESHOLD_MS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
charTyped
(char pCodePoint, int pModifiers) Called when a character is typed within the GUI element.protected MutableComponent
void
deleteChars
(int pNum) 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.void
deleteCharsToPos
(int pNum) private void
deleteText
(int pCount) void
deleteWords
(int pNum) 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 int
getCursorPos
(int pDelta) int
int
private int
int
getScreenX
(int pCharNum) boolean
getValue()
int
getWordPosition
(int pNumWords) Gets the starting index of the word at the specified number of words away from the cursor position.private int
getWordPosition
(int pNumWords, int pPos) Gets the starting index of the word at a distance of the specified number of words away from the given position.private int
getWordPosition
(int pNumWords, int pPos, boolean pSkipConsecutiveSpaces) Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spacesvoid
insertText
(String pTextToWrite) Adds the given text after the cursor, or replaces the currently selected text if there is a selection.boolean
private boolean
boolean
boolean
keyPressed
(int pKeyCode, int pScanCode, int pModifiers) Called when a keyboard key is pressed within the GUI element.void
moveCursor
(int pDelta, boolean pSelect) void
moveCursorTo
(int pDelta, boolean pSelect) void
moveCursorToEnd
(boolean pSelect) void
moveCursorToStart
(boolean pSelect) void
onClick
(double pMouseX, double pMouseY) private void
onValueChange
(String pNewText) void
playDownSound
(SoundManager pHandler) private void
renderHighlight
(GuiGraphics pGuiGraphics, int pMinX, int pMinY, int pMaxX, int pMaxY) void
renderWidget
(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) private void
scrollTo
(int pPosition) void
setBordered
(boolean pEnableBackgroundDrawing) Sets whether the background and outline of this text box should be drawn.void
setCanLoseFocus
(boolean pCanLoseFocus) Sets whether this text box loses focus when something other than it is clicked.void
setCursorPosition
(int pPos) void
setEditable
(boolean pEnabled) Sets whether this text box is enabled.void
void
setFocused
(boolean pFocused) Sets the focus state of the GUI element.void
setFormatter
(BiFunction<String, Integer, FormattedCharSequence> pTextFormatter) void
setHighlightPos
(int pPosition) Sets the position of the selection anchor (the selection anchor and the cursor position mark the edges of the selection).void
void
setMaxLength
(int pLength) Sets the maximum length for the text in this text box.void
setResponder
(Consumer<String> pResponder) void
setSuggestion
(String pSuggestion) void
setTextColor
(int pColor) Sets the color to use when drawing this text box's text.void
setTextColorUneditable
(int pColor) Sets the color to use for text in this text box when this text box is disabled.void
setTextShadow
(boolean textShadow) void
Sets the text of the textbox, and moves the cursor to the end.void
setVisible
(boolean pIsVisible) Sets whether this textbox is visible.void
updateWidgetNarration
(NarrationElementOutput pNarrationElementOutput) 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, wrapDefaultNarrationMessage
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
getCurrentFocusPath, keyReleased, mouseMoved, mouseScrolled
Methods inherited from interface net.neoforged.neoforge.client.extensions.IAbstractWidgetExtension
onClick
Methods inherited from interface net.minecraft.client.gui.layouts.LayoutElement
setPosition
Methods 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:
createNarrationMessage
in 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 pCount) -
deleteWords
public void deleteWords(int pNum) 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 pNum) 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 pNum) -
getWordPosition
public int getWordPosition(int pNumWords) Gets the starting index of the word at the specified number of words away from the cursor position. -
getWordPosition
private int getWordPosition(int pNumWords, int pPos) 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 pNumWords, int pPos, boolean pSkipConsecutiveSpaces) Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spaces -
moveCursor
public void moveCursor(int pDelta, boolean pSelect) -
getCursorPos
private int getCursorPos(int pDelta) -
moveCursorTo
public void moveCursorTo(int pDelta, boolean pSelect) -
setCursorPosition
public void setCursorPosition(int pPos) -
moveCursorToStart
public void moveCursorToStart(boolean pSelect) -
moveCursorToEnd
public void moveCursorToEnd(boolean pSelect) -
keyPressed
public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) Called when a keyboard key is pressed within the GUI element.- Specified by:
keyPressed
in interfaceGuiEventListener
- Parameters:
pKeyCode
- the key code of the pressed key.pScanCode
- the scan code of the pressed key.pModifiers
- the keyboard modifiers.- Returns:
true
if the event is consumed,false
otherwise.
-
canConsumeInput
public boolean canConsumeInput() -
charTyped
public boolean charTyped(char pCodePoint, int pModifiers) Called when a character is typed within the GUI element.- Specified by:
charTyped
in interfaceGuiEventListener
- Parameters:
pCodePoint
- the code point of the typed character.pModifiers
- the keyboard modifiers.- Returns:
true
if the event is consumed,false
otherwise.
-
onClick
public void onClick(double pMouseX, double pMouseY) - Overrides:
onClick
in classAbstractWidget
-
playDownSound
- Overrides:
playDownSound
in classAbstractWidget
-
renderWidget
- Specified by:
renderWidget
in classAbstractWidget
-
renderHighlight
-
setMaxLength
public void setMaxLength(int pLength) 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 pEnableBackgroundDrawing) Sets whether the background and outline of this text box should be drawn. -
setTextColor
public void setTextColor(int pColor) 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 pColor) Sets the color to use for text in this text box when this text box is disabled. -
setFocused
public void setFocused(boolean pFocused) Sets the focus state of the GUI element.- Specified by:
setFocused
in interfaceGuiEventListener
- Overrides:
setFocused
in classAbstractWidget
- Parameters:
pFocused
-true
to apply focus,false
to remove focus
-
isEditable
private boolean isEditable() -
setEditable
public void setEditable(boolean pEnabled) Sets whether this text box is enabled. Disabled text boxes cannot be typed in. -
getInnerWidth
public int getInnerWidth() -
setHighlightPos
public void setHighlightPos(int pPosition) 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 pPosition) -
setCanLoseFocus
public void setCanLoseFocus(boolean pCanLoseFocus) Sets whether this text box loses focus when something other than it is clicked. -
isVisible
public boolean isVisible() -
setVisible
public void setVisible(boolean pIsVisible) Sets whether this textbox is visible. -
setSuggestion
-
getScreenX
public int getScreenX(int pCharNum) -
updateWidgetNarration
- Specified by:
updateWidgetNarration
in classAbstractWidget
-
setHint
-
setTextShadow
public void setTextShadow(boolean textShadow) -
getTextShadow
public boolean getTextShadow()
-