@Environment(value=CLIENT) public class TextFieldWidget extends AbstractButtonWidget implements Drawable, Element
Modifier and Type | Field and 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 |
active, alpha, height, hovered, nextNarration, visible, WIDGETS_LOCATION, width, x, y
GUI_ICONS_TEXTURE, OPTIONS_BACKGROUND_TEXTURE, STATS_ICON_TEXTURE
Constructor and Description |
---|
TextFieldWidget(TextRenderer textRenderer,
int x,
int y,
int width,
int height,
Text text) |
TextFieldWidget(TextRenderer textRenderer,
int x,
int y,
int width,
int height,
TextFieldWidget copyFrom,
Text text) |
Modifier and Type | Method and 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) |
clicked, getHeight, getMessage, getWidth, getYImage, isFocused, isHovered, isValidClickButton, mouseDragged, mouseReleased, narrate, onClick, onDrag, onRelease, playDownSound, queueNarration, render, renderBg, renderToolTip, setAlpha, setFocused, setMessage, setWidth
drawCenteredString, drawCenteredText, drawHorizontalLine, drawSprite, drawStringWithShadow, drawTexture, drawTexture, drawTexture, drawTexture, drawTextWithShadow, drawVerticalLine, fill, fillGradient, fillGradient, getZOffset, method_29343, setZOffset
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
keyReleased, mouseDragged, mouseMoved, mouseReleased, mouseScrolled
private final TextRenderer textRenderer
private String text
private int maxLength
private int focusedTicks
private boolean focused
private boolean focusUnlocked
private boolean editable
private boolean selecting
private int firstCharacterIndex
private int selectionStart
private int selectionEnd
private int editableColor
private int uneditableColor
private String suggestion
private BiFunction<String,Integer,OrderedText> renderTextProvider
public TextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text)
public TextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text)
public void setRenderTextProvider(BiFunction<String,Integer,OrderedText> renderTextProvider)
public void tick()
protected MutableText getNarrationMessage()
getNarrationMessage
in class AbstractButtonWidget
public void setText(String text)
public String getText()
public String getSelectedText()
public void write(String string)
private void onChanged(String newText)
private void erase(int offset)
public void eraseWords(int wordOffset)
public void eraseCharacters(int characterOffset)
public int getWordSkipPosition(int wordOffset)
private int getWordSkipPosition(int wordOffset, int cursorPosition)
private int getWordSkipPosition(int wordOffset, int cursorPosition, boolean skipOverSpaces)
public void moveCursor(int offset)
private int method_27537(int int2)
public void setCursor(int cursor)
public void setSelectionStart(int cursor)
public void setCursorToStart()
public void setCursorToEnd()
public boolean keyPressed(int keyCode, int scanCode, int modifiers)
GLFW
class.keyPressed
in interface Element
keyCode
- the named key code of the event as described in the GLFW
classscanCode
- the unique/platform-specific scan code of the keyboard inputmodifiers
- a GLFW bitfield describing the modifier keys that are held down (see GLFW Modifier key flags)true
to indicate that the event handling is successful/validKeyboard.onKey(long, int, int, int, int)
,
GLFW.GLFW_KEY_Q
,
GLFWKeyCallbackI.invoke(long, int, int, int, int)
public boolean isActive()
public boolean charTyped(char chr, int keyCode)
GLFW
class.charTyped
in interface Element
chr
- the captured characterkeyCode
- the associated key codetrue
to indicate that the event handling is successful/validKeyboard.onChar(long, int, int)
,
GLFW.GLFW_KEY_Q
,
GLFWKeyCallbackI.invoke(long, int, int, int, int)
public boolean mouseClicked(double mouseX, double mouseY, int button)
GLFW
class.mouseClicked
in interface Element
mouseClicked
in class AbstractButtonWidget
mouseX
- the X coordinate of the mousemouseY
- the Y coordinate of the mousebutton
- the mouse button numbertrue
to indicate that the event handling is successful/validMouse.onMouseButton(long, int, int, int)
,
GLFW.GLFW_MOUSE_BUTTON_1
public void setSelected(boolean selected)
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta)
renderButton
in class AbstractButtonWidget
private void drawSelectionHighlight(int x1, int y1, int x2, int y2)
public void setMaxLength(int maxLength)
private int getMaxLength()
public int getCursor()
private boolean hasBorder()
public void setHasBorder(boolean hasBorder)
public void setEditableColor(int color)
public void setUneditableColor(int color)
public boolean changeFocus(boolean lookForwards)
changeFocus
in interface Element
changeFocus
in class AbstractButtonWidget
lookForwards
- true
to cycle forwards, otherwise cycle backwardstrue
to indicate that the event handling is successful/validpublic boolean isMouseOver(double mouseX, double mouseY)
isMouseOver
in interface Element
isMouseOver
in class AbstractButtonWidget
mouseX
- the X coordinate of the mousemouseY
- the Y coordinate of the mousetrue
if the mouse is within the bound of the element, otherwise false
protected void onFocusedChanged(boolean bool)
onFocusedChanged
in class AbstractButtonWidget
private boolean isEditable()
public void setEditable(boolean editable)
public int getInnerWidth()
public void setSelectionEnd(int int2)
public void setFocusUnlocked(boolean focusUnlocked)
public boolean isVisible()
public void setVisible(boolean visible)
public int getCharacterX(int index)
public void setX(int x)