Class WTextField
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WTextField
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(net.minecraft.client.gui.narration.NarrationElementOutput builder) Adds the narrations of this widget to a narration builder.booleancanFocus()Tests whether this widget can have the focus in the GUI.booleanTests whether this widget can have the focus in the GUI for text input.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).intgetCaretPosition(int clickX) intint@Nullable net.minecraft.network.chat.ComponentgetText()Returns the text in this text field.booleanonCharTyped(net.minecraft.client.input.CharacterEvent input) Notifies this widget that a character has been typed.onClick(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) Notifies this widget that the mouse has been pressed and released, both while inside its bounds.voidonDirectionalKey(int direction, net.minecraft.client.input.KeyEvent input) voidNotifies this widget that it has gained focusonKeyPressed(net.minecraft.client.input.KeyEvent input) Notifies this widget that a key has been pressed.onPreeditUpdated(@Nullable net.minecraft.client.input.PreeditEvent event) Notifies this widget the preedit overlay has been updated.voidpaint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Paints this widget.protected voidrenderBox(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y) protected voidrenderCursor(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, String visibleText) protected voidrenderPreeditOverlay(net.minecraft.client.gui.GuiGraphicsExtractor graphics, int x, int y, String visibleText, @Nullable net.minecraft.client.gui.components.IMEPreeditOverlay overlay) Renders the IME preedit overlay.protected voidrenderSelection(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, String visibleText) protected voidrenderSuggestion(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y) protected voidrenderText(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, String visibleText) protected voidrenderTextField(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y) voidsetChangedListener(Consumer<String> listener) voidsetCursorPos(int location) setDisabledColor(int col) setEditable(boolean editable) setEnabledColor(int col) setMaxLength(int max) voidsetSize(int x, int y) Sets the size of this widget.setSuggestion(@Nullable net.minecraft.network.chat.Component suggestion) setSuggestionColor(int suggestionColor) voidSets the text of this text field.setTextPredicate(Predicate<String> predicate_1) voidtick()Executes a client-side tick for this widget.Methods inherited from class WWidget
addPainters, addTooltip, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onFocusLost, onHidden, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, shouldRenderInDarkMode, validate
-
Field Details
-
TEXT_PADDING_X
public static final int TEXT_PADDING_X- See Also:
-
TEXT_PADDING_Y
public static final int TEXT_PADDING_Y- See Also:
-
CURSOR_PADDING_Y
public static final int CURSOR_PADDING_Y- See Also:
-
CURSOR_HEIGHT
public static final int CURSOR_HEIGHT- See Also:
-
-
Constructor Details
-
WTextField
public WTextField() -
WTextField
public WTextField(net.minecraft.network.chat.Component suggestion)
-
-
Method Details
-
setText
Sets the text of this text field. If the text is more than the max length, it'll be shortened to the max length.- Parameters:
s- the new text
-
getText
-
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
tick
-
setSize
-
setCursorPos
public void setCursorPos(int location) -
getMaxLength
public int getMaxLength() -
getCursor
public int getCursor() -
scrollCursorIntoView
@Environment(CLIENT) public void scrollCursorIntoView() -
getSelection
-
isEditable
public boolean isEditable() -
renderBox
@Environment(CLIENT) protected void renderBox(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y) -
renderText
@Environment(CLIENT) protected void renderText(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, String visibleText) -
renderCursor
@Environment(CLIENT) protected void renderCursor(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, String visibleText) -
renderSuggestion
@Environment(CLIENT) protected void renderSuggestion(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y) -
renderSelection
@Environment(CLIENT) protected void renderSelection(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, String visibleText) -
renderPreeditOverlay
-
renderTextField
@Environment(CLIENT) protected void renderTextField(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y) -
setTextPredicate
-
setChangedListener
-
setMaxLength
-
setEnabledColor
-
setSuggestionColor
-
setDisabledColor
-
setEditable
-
getSuggestion
-
setSuggestion
-
canFocus
-
canFocusForTextInput
public boolean canFocusForTextInput()Description copied from class:WWidgetTests whether this widget can have the focus in the GUI for text input.Text input widgets must override this to provide proper input method editor support.
- Overrides:
canFocusForTextInputin classWWidget- Returns:
- true if this widget can be focused for text input, false otherwise
-
onFocusGained
public void onFocusGained()Description copied from class:WWidgetNotifies this widget that it has gained focus- Overrides:
onFocusGainedin classWWidget
-
paint
@Environment(CLIENT) public void paint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Description copied from class:WWidgetPaints this widget. -
onClick
@Environment(CLIENT) public InputResult onClick(net.minecraft.client.input.MouseButtonEvent click, boolean doubled) Description copied from class:WWidgetNotifies this widget that the mouse has been pressed and released, both while inside its bounds.- Overrides:
onClickin classWWidget- Parameters:
click- the click data whose coordinates are in widget space ((0, 0) is the top-left point of this widget)doubled-trueif this is a double click,falseotherwise- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
getCaretPosition
@Environment(CLIENT) public int getCaretPosition(int clickX) -
onCharTyped
@Environment(CLIENT) public InputResult onCharTyped(net.minecraft.client.input.CharacterEvent input) Description copied from class:WWidgetNotifies this widget that a character has been typed. This method is subject to key repeat, and may be called for characters that do not directly have a corresponding keyboard key.- Overrides:
onCharTypedin classWWidget- Parameters:
input- the character typed- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onDirectionalKey
@Environment(CLIENT) public void onDirectionalKey(int direction, net.minecraft.client.input.KeyEvent input) -
onKeyPressed
Description copied from class:WWidgetNotifies this widget that a key has been pressed.- Overrides:
onKeyPressedin classWWidget- Parameters:
input- the key input- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onPreeditUpdated
@Environment(CLIENT) public InputResult onPreeditUpdated(@Nullable net.minecraft.client.input.PreeditEvent event) Description copied from class:WWidgetNotifies this widget the preedit overlay has been updated.- Overrides:
onPreeditUpdatedin classWWidget- Parameters:
event- the preedit event- Returns:
InputResult.PROCESSEDif the event was handled,InputResult.IGNOREDotherwise.
-
addNarrations
public void addNarrations(net.minecraft.client.gui.narration.NarrationElementOutput builder) Description copied from class:WWidgetAdds the narrations of this widget to a narration builder. Narrations will only apply if this widget is narratable.The widget needs to be focusable or hoverable, and also be focused/hovered for narrations to be added.
- Overrides:
addNarrationsin classWWidget- Parameters:
builder- the narration builder, cannot be null
-