Package net.minecraft.client.gui.widget
Class TextFieldWidget
java.lang.Object
net.minecraft.client.gui.DrawableHelper
net.minecraft.client.gui.widget.AbstractButtonWidget
net.minecraft.client.gui.widget.TextFieldWidget
@Environment(CLIENT) public class TextFieldWidget extends AbstractButtonWidget implements Drawable, Element
-
Field Summary
Fields Modifier and Type Field Description private Consumer<String>
changedListener
private boolean
editable
private int
editableColor
private int
firstCharacterIndex
private boolean
focused
private int
focusedTicks
private boolean
focusUnlocked
private int
maxLength
private BiFunction<String,Integer,OrderedText>
renderTextProvider
private boolean
selecting
private int
selectionEnd
private int
selectionStart
private String
suggestion
private String
text
private Predicate<String>
textPredicate
private TextRenderer
textRenderer
private int
uneditableColor
Fields inherited from class net.minecraft.client.gui.widget.AbstractButtonWidget
active, alpha, height, hovered, nextNarration, visible, WIDGETS_LOCATION, width, x, y
Fields inherited from class net.minecraft.client.gui.DrawableHelper
GUI_ICONS_TEXTURE, OPTIONS_BACKGROUND_TEXTURE, STATS_ICON_TEXTURE
-
Constructor Summary
Constructors Constructor Description TextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, TextFieldWidget copyFrom, Text text)
TextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text)
-
Method Summary
Modifier and Type Method Description boolean
changeFocus(boolean lookForwards)
Changes the focusing element by cycling to the next/previous element.boolean
charTyped(char chr, int keyCode)
Callback for when a character input has been captured.private void
drawSelectionHighlight(int x1, int y1, int x2, int y2)
private void
erase(int offset)
void
eraseCharacters(int characterOffset)
void
eraseWords(int wordOffset)
int
getCharacterX(int index)
int
getCursor()
int
getInnerWidth()
private int
getMaxLength()
protected MutableText
getNarrationMessage()
String
getSelectedText()
String
getText()
int
getWordSkipPosition(int wordOffset)
private int
getWordSkipPosition(int wordOffset, int cursorPosition)
private int
getWordSkipPosition(int wordOffset, int cursorPosition, boolean skipOverSpaces)
private boolean
hasBorder()
boolean
isActive()
private boolean
isEditable()
boolean
isMouseOver(double mouseX, double mouseY)
Checks if the mouse position is within the bound of the element.boolean
isVisible()
boolean
keyPressed(int keyCode, int scanCode, int modifiers)
Callback for when a key down event has been captured.private int
method_27537(int int2)
boolean
mouseClicked(double mouseX, double mouseY, int button)
Callback for when a mouse button down event has been captured.void
moveCursor(int offset)
private void
onChanged(String newText)
protected void
onFocusedChanged(boolean bool)
void
renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta)
void
setChangedListener(Consumer<String> changedListener)
void
setCursor(int cursor)
void
setCursorToEnd()
void
setCursorToStart()
void
setEditable(boolean editable)
void
setEditableColor(int color)
void
setFocusUnlocked(boolean focusUnlocked)
void
setHasBorder(boolean hasBorder)
void
setMaxLength(int maxLength)
void
setRenderTextProvider(BiFunction<String,Integer,OrderedText> renderTextProvider)
void
setSelected(boolean selected)
void
setSelectionEnd(int int2)
void
setSelectionStart(int cursor)
void
setSuggestion(String suggestion)
void
setText(String text)
void
setTextPredicate(Predicate<String> textPredicate)
void
setUneditableColor(int color)
void
setVisible(boolean visible)
void
setX(int x)
void
tick()
void
write(String string)
Methods inherited from class net.minecraft.client.gui.widget.AbstractButtonWidget
clicked, getHeight, getMessage, getWidth, getYImage, isFocused, isHovered, isValidClickButton, mouseDragged, mouseReleased, narrate, onClick, onDrag, onRelease, playDownSound, queueNarration, render, renderBg, renderToolTip, setAlpha, setFocused, setMessage, setWidth
Methods inherited from class net.minecraft.client.gui.DrawableHelper
drawCenteredString, drawCenteredText, drawHorizontalLine, drawSprite, drawStringWithShadow, drawTexture, drawTexture, drawTexture, drawTexture, drawTextWithShadow, drawVerticalLine, fill, fillGradient, fillGradient, getZOffset, method_29343, setZOffset
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.Element
keyReleased, mouseDragged, mouseMoved, mouseReleased, mouseScrolled
-
Field Details
-
textRenderer
-
text
-
maxLength
private int maxLength -
focusedTicks
private int focusedTicks -
focused
private boolean focused -
focusUnlocked
private boolean focusUnlocked -
editable
private boolean editable -
selecting
private boolean selecting -
firstCharacterIndex
private int firstCharacterIndex -
selectionStart
private int selectionStart -
selectionEnd
private int selectionEnd -
editableColor
private int editableColor -
uneditableColor
private int uneditableColor -
suggestion
-
changedListener
-
textPredicate
-
renderTextProvider
-
-
Constructor Details
-
TextFieldWidget
-
TextFieldWidget
public TextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text)
-
-
Method Details
-
setChangedListener
-
setRenderTextProvider
-
tick
public void tick() -
getNarrationMessage
- Overrides:
getNarrationMessage
in classAbstractButtonWidget
-
setText
-
getText
-
getSelectedText
-
setTextPredicate
-
write
-
onChanged
-
erase
private void erase(int offset) -
eraseWords
public void eraseWords(int wordOffset) -
eraseCharacters
public void eraseCharacters(int characterOffset) -
getWordSkipPosition
public int getWordSkipPosition(int wordOffset) -
getWordSkipPosition
private int getWordSkipPosition(int wordOffset, int cursorPosition) -
getWordSkipPosition
private int getWordSkipPosition(int wordOffset, int cursorPosition, boolean skipOverSpaces) -
moveCursor
public void moveCursor(int offset) -
method_27537
private int method_27537(int int2) -
setCursor
public void setCursor(int cursor) -
setSelectionStart
public void setSelectionStart(int cursor) -
setCursorToStart
public void setCursorToStart() -
setCursorToEnd
public void setCursorToEnd() -
keyPressed
public boolean keyPressed(int keyCode, int scanCode, int modifiers)Callback for when a key down event has been captured. The key code is identified by the constants inGLFW
class.- Specified by:
keyPressed
in interfaceElement
- Parameters:
keyCode
- the named key code of the event as described in theGLFW
classscanCode
- the unique/platform-specific scan code of the keyboard inputmodifiers
- a GLFW bitfield describing the modifier keys that are held down (see {@linkplain https://www.glfw.org/docs/3.3/group__mods.html GLFW Modifier key flags})- Returns:
true
to indicate that the event handling is successful/valid- See Also:
Keyboard.onKey(long, int, int, int, int)
,GLFW.GLFW_KEY_Q
,GLFWKeyCallbackI.invoke(long, int, int, int, int)
-
isActive
public boolean isActive() -
charTyped
public boolean charTyped(char chr, int keyCode)Callback for when a character input has been captured. The key code is identified by the constants inGLFW
class.- Specified by:
charTyped
in interfaceElement
- Parameters:
chr
- the captured characterkeyCode
- the associated key code- Returns:
true
to indicate that the event handling is successful/valid- See Also:
Keyboard.onChar(long, int, int)
,GLFW.GLFW_KEY_Q
,GLFWKeyCallbackI.invoke(long, int, int, int, int)
-
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button)Callback for when a mouse button down event has been captured. The button number is identified by the constants inGLFW
class.- Specified by:
mouseClicked
in interfaceElement
- Overrides:
mouseClicked
in classAbstractButtonWidget
- Parameters:
mouseX
- the X coordinate of the mousemouseY
- the Y coordinate of the mousebutton
- the mouse button number- Returns:
true
to indicate that the event handling is successful/valid- See Also:
Mouse.onMouseButton(long, int, int, int)
,GLFW.GLFW_MOUSE_BUTTON_1
-
setSelected
public void setSelected(boolean selected) -
renderButton
- Overrides:
renderButton
in classAbstractButtonWidget
-
drawSelectionHighlight
private void drawSelectionHighlight(int x1, int y1, int x2, int y2) -
setMaxLength
public void setMaxLength(int maxLength) -
getMaxLength
private int getMaxLength() -
getCursor
public int getCursor() -
hasBorder
private boolean hasBorder() -
setHasBorder
public void setHasBorder(boolean hasBorder) -
setEditableColor
public void setEditableColor(int color) -
setUneditableColor
public void setUneditableColor(int color) -
changeFocus
public boolean changeFocus(boolean lookForwards)Changes the focusing element by cycling to the next/previous element. This action is done typically when the user has pressed the 'Tab' or 'Ctrl+Tab' key.- Specified by:
changeFocus
in interfaceElement
- Overrides:
changeFocus
in classAbstractButtonWidget
- Parameters:
lookForwards
-true
to cycle forwards, otherwise cycle backwards- Returns:
true
to indicate that the event handling is successful/valid
-
isMouseOver
public boolean isMouseOver(double mouseX, double mouseY)Checks if the mouse position is within the bound of the element.- Specified by:
isMouseOver
in interfaceElement
- Overrides:
isMouseOver
in classAbstractButtonWidget
- Parameters:
mouseX
- the X coordinate of the mousemouseY
- the Y coordinate of the mouse- Returns:
true
if the mouse is within the bound of the element, otherwisefalse
-
onFocusedChanged
protected void onFocusedChanged(boolean bool)- Overrides:
onFocusedChanged
in classAbstractButtonWidget
-
isEditable
private boolean isEditable() -
setEditable
public void setEditable(boolean editable) -
getInnerWidth
public int getInnerWidth() -
setSelectionEnd
public void setSelectionEnd(int int2) -
setFocusUnlocked
public void setFocusUnlocked(boolean focusUnlocked) -
isVisible
public boolean isVisible() -
setVisible
public void setVisible(boolean visible) -
setSuggestion
-
getCharacterX
public int getCharacterX(int index) -
setX
public void setX(int x)
-