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(NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.booleancanFocus()Tests whether this widget can have the focus in the GUI.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).intgetCaretPosition(int clickX) intintgetText()Returns the text in this text field.booleanonCharTyped(char ch) Notifies this widget that a character has been typed.onClick(int x, int y, int button) Notifies this widget that the mouse has been pressed and released, both while inside its bounds.voidonDirectionalKey(int direction, int modifiers) voidNotifies this widget that it has gained focusonKeyPressed(int ch, int key, int modifiers) Notifies this widget that a key has been pressed.voidpaint(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.protected voidrenderBox(DrawContext context, int x, int y) protected voidrenderCursor(DrawContext context, int x, int y, String visibleText) protected voidrenderSelection(DrawContext context, int x, int y, String visibleText) protected voidrenderSuggestion(DrawContext context, int x, int y) protected voidrenderText(DrawContext context, int x, int y, String visibleText) protected voidrenderTextField(DrawContext 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 Text 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 io.github.cottonmc.cotton.gui.widget.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
-
-
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
Returns the text in this text field.- Returns:
- the text in this text field
-
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
tick
public void tick()Description copied from class:WWidgetExecutes a client-side tick for this widget. -
setSize
public void setSize(int x, int y) Description copied from class:WWidgetSets the size of this widget.Overriding methods may restrict one of the dimensions to be a constant value, for example
super.setSize(x, 20). -
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
-
renderText
@Environment(CLIENT) protected void renderText(DrawContext context, int x, int y, String visibleText) -
renderCursor
@Environment(CLIENT) protected void renderCursor(DrawContext context, int x, int y, String visibleText) -
renderSuggestion
-
renderSelection
@Environment(CLIENT) protected void renderSelection(DrawContext context, int x, int y, String visibleText) -
renderTextField
-
setTextPredicate
-
setChangedListener
-
setMaxLength
-
setEnabledColor
-
setSuggestionColor
-
setDisabledColor
-
setEditable
-
getSuggestion
-
setSuggestion
-
canFocus
public boolean canFocus()Description copied from class:WWidgetTests whether this widget can have the focus in the GUI. -
onFocusGained
public void onFocusGained()Description copied from class:WWidgetNotifies this widget that it has gained focus- Overrides:
onFocusGainedin classWWidget
-
paint
Description copied from class:WWidgetPaints this widget. -
onClick
Description copied from class:WWidgetNotifies this widget that the mouse has been pressed and released, both while inside its bounds.- Overrides:
onClickin classWWidget- Parameters:
x- The X coordinate of the event, in widget-space (0 is the left edge of this widget)y- The Y coordinate of the event, in widget-space (0 is the top edge of this widget)button- The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
getCaretPosition
@Environment(CLIENT) public int getCaretPosition(int clickX) -
onCharTyped
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:
ch- the character typed- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onDirectionalKey
@Environment(CLIENT) public void onDirectionalKey(int direction, int modifiers) -
onKeyPressed
Description copied from class:WWidgetNotifies this widget that a key has been pressed.- Overrides:
onKeyPressedin classWWidget- Parameters:
key- the GLFW scancode of the key- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
addNarrations
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
-