Class TextInputWidget
java.lang.Object
net.minecraft.client.gui.widget.ClickableWidget
net.uku3lig.ukulib.config.option.widget.TextInputWidget
- All Implemented Interfaces:
net.minecraft.client.gui.Drawable,net.minecraft.client.gui.Element,net.minecraft.client.gui.Narratable,net.minecraft.client.gui.navigation.Navigable,net.minecraft.client.gui.Selectable,net.minecraft.client.gui.widget.Widget,CheckedOption
- Direct Known Subclasses:
ColorInputWidget
public class TextInputWidget
extends net.minecraft.client.gui.widget.ClickableWidget
implements net.minecraft.client.gui.Drawable, CheckedOption
A widget to input text. Based on
TextFieldWidget.-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.client.gui.Selectable
net.minecraft.client.gui.Selectable.SelectionType -
Field Summary
Fields inherited from class net.minecraft.client.gui.widget.ClickableWidget
active, alpha, height, hovered, visible, widthFields inherited from interface net.minecraft.client.gui.Element
MAX_DOUBLE_CLICK_INTERVAL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidappendClickableNarrations(net.minecraft.client.gui.screen.narration.NarrationMessageBuilder builder) booleancharTyped(char chr, int modifiers) voideraseCharacters(int characterOffset) Erases characters depending on thecharacterOffset.voideraseWords(int wordOffset) Erases words depending on thewordOffset.intReturns the position of the cursor, or the beginning of the selection.intReturns width of the text field, without the border.intThe maximum length of the text.protected net.minecraft.text.MutableText@Nullable net.minecraft.client.gui.navigation.GuiNavigationPathgetNavigationPath(net.minecraft.client.gui.navigation.GuiNavigation navigation) Gets the currently selected text, if any.getText()The text.intgetWordSkipPosition(int wordOffset) Gets the position of the word to skip to.booleanChecks if the text field is inactive.booleanisMouseOver(double mouseX, double mouseY) booleanisValid()Checks if the option is valid.booleanWhether the text field is currently visible.booleankeyPressed(int keyCode, int scanCode, int modifiers) booleanmouseClicked(double mouseX, double mouseY, int button) voidmoveCursor(int offset) Moves the cursor by the specified offset.voidrenderWidget(net.minecraft.client.gui.DrawContext drawContext, int mouseX, int mouseY, float delta) voidsetCursor(int cursor) Sets the cursor position.voidSets the cursor position to the end of the text.voidSets the cursor position to the start of the text.voidsetSelectionEnd(int index) Sets the end of the selection.voidsetSelectionStart(int cursor) Sets the start of the selection.voidSets the text.voidWrites the given text to the current cursor position.Methods inherited from class net.minecraft.client.gui.widget.ClickableWidget
appendDefaultNarrations, appendNarrations, clicked, drawScrollableText, drawScrollableText, drawScrollableText, forEachChild, getBottom, getHeight, getMessage, getNarrationMessage, getNavigationFocus, getNavigationOrder, getRight, getTooltip, getType, getWidth, getX, getY, isFocused, isHovered, isNarratable, isSelected, isValidClickButton, mouseDragged, mouseReleased, onClick, onDrag, onRelease, playDownSound, render, setAlpha, setDimensions, setDimensionsAndPosition, setFocused, setHeight, setMessage, setNavigationOrder, setTooltip, setTooltipDelay, setWidth, setX, setYMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.client.gui.Drawable
renderMethods inherited from interface net.minecraft.client.gui.Element
getFocusedPath, keyReleased, mouseMoved, mouseScrolledMethods inherited from interface net.minecraft.client.gui.widget.Widget
setPosition
-
Constructor Details
-
TextInputWidget
public TextInputWidget(int x, int y, int width, int height, String initialValue, Consumer<String> changedListener, String suggestion, Predicate<String> textPredicate, int maxLength) Constructor.- Parameters:
x- the x positiony- the y positionwidth- the widthheight- the heightinitialValue- the initial valuechangedListener- the callback to set the valuesuggestion- the suggestiontextPredicate- the predicate to check the textmaxLength- the maximum length of the text
-
-
Method Details
-
getNarrationMessage
protected net.minecraft.text.MutableText getNarrationMessage()- Overrides:
getNarrationMessagein classnet.minecraft.client.gui.widget.ClickableWidget
-
setText
Sets the text.- Parameters:
text- the new text
-
getSelectedText
Gets the currently selected text, if any.- Returns:
- the selected text
-
write
Writes the given text to the current cursor position.- Parameters:
text- the text to write
-
eraseWords
public void eraseWords(int wordOffset) Erases words depending on thewordOffset.- Parameters:
wordOffset- the offset
-
eraseCharacters
public void eraseCharacters(int characterOffset) Erases characters depending on thecharacterOffset.- Parameters:
characterOffset- the offset
-
getWordSkipPosition
public int getWordSkipPosition(int wordOffset) Gets the position of the word to skip to. Used for deleting words.- Parameters:
wordOffset- the offset- Returns:
- the position of the word to skip to
- See Also:
-
getWordSkipPosition(int, int)
-
moveCursor
public void moveCursor(int offset) Moves the cursor by the specified offset.- Parameters:
offset- the offset
-
setCursor
public void setCursor(int cursor) Sets the cursor position.- Parameters:
cursor- the cursor position
-
setSelectionStart
public void setSelectionStart(int cursor) Sets the start of the selection.- Parameters:
cursor- the start of the selection
-
setCursorToStart
public void setCursorToStart()Sets the cursor position to the start of the text. -
setCursorToEnd
public void setCursorToEnd()Sets the cursor position to the end of the text. -
keyPressed
public boolean keyPressed(int keyCode, int scanCode, int modifiers) - Specified by:
keyPressedin interfacenet.minecraft.client.gui.Element
-
isInactive
public boolean isInactive()Checks if the text field is inactive.- Returns:
trueif the text field is inactive,falseotherwise
-
charTyped
public boolean charTyped(char chr, int modifiers) - Specified by:
charTypedin interfacenet.minecraft.client.gui.Element
-
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button) - Specified by:
mouseClickedin interfacenet.minecraft.client.gui.Element- Overrides:
mouseClickedin classnet.minecraft.client.gui.widget.ClickableWidget
-
renderWidget
public void renderWidget(net.minecraft.client.gui.DrawContext drawContext, int mouseX, int mouseY, float delta) - Specified by:
renderWidgetin classnet.minecraft.client.gui.widget.ClickableWidget
-
getCursor
public int getCursor()Returns the position of the cursor, or the beginning of the selection.- Returns:
- the cursor position
-
isMouseOver
public boolean isMouseOver(double mouseX, double mouseY) - Specified by:
isMouseOverin interfacenet.minecraft.client.gui.Element- Overrides:
isMouseOverin classnet.minecraft.client.gui.widget.ClickableWidget
-
getInnerWidth
public int getInnerWidth()Returns width of the text field, without the border.- Returns:
- the inner width
-
setSelectionEnd
public void setSelectionEnd(int index) Sets the end of the selection.- Parameters:
index- the end of the selection
-
isVisible
public boolean isVisible()Whether the text field is currently visible.- Returns:
trueif the text field is visible,falseotherwise
-
appendClickableNarrations
public void appendClickableNarrations(net.minecraft.client.gui.screen.narration.NarrationMessageBuilder builder) - Specified by:
appendClickableNarrationsin classnet.minecraft.client.gui.widget.ClickableWidget
-
isValid
public boolean isValid()Description copied from interface:CheckedOptionChecks if the option is valid.- Specified by:
isValidin interfaceCheckedOption- Returns:
- true if the option is valid, false otherwise
-
getText
The text.- Returns:
- the text
-
getMaxLength
public int getMaxLength()The maximum length of the text.- Returns:
- the maximum length of the text
-