Class WTextField
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WTextField
-
Field Summary
Fields -
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).static intgetCaretOffset(String s, int pos) From a caret position, finds out what the x-offset to draw the caret is.static intgetCaretPos(String s, int x) From an X offset past the left edge of a TextRenderer.draw, finds out what the closest caret position (division between letters) is.intintgetText()booleanvoidonCharTyped(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.voidNotifies this widget that it has gained focusvoidonKeyPressed(int ch, int key, int modifiers) Notifies this widget that a key has been pressed.voidpaint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) Paints this widget.protected voidrenderTextField(MatrixStack matrices, int x, int y) setBackgroundPainter(BackgroundPainter painter) setChangedListener(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 String suggestion) setSuggestion(@Nullable Text suggestion) voidsetTextPredicate(Predicate<String> predicate_1) Methods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addPainters, addTooltip, canHover, cycleFocus, getAbsoluteX, getAbsoluteY, 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, tick, validate
-
Field Details
-
OFFSET_X_TEXT
public static final int OFFSET_X_TEXT- See Also:
-
-
Constructor Details
-
WTextField
public WTextField() -
WTextField
-
-
Method Details
-
setText
-
getText
-
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
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() -
getSelection
-
isEditable
public boolean isEditable() -
renderTextField
-
setTextPredicate
-
setChangedListener
-
setMaxLength
-
setEnabledColor
-
setDisabledColor
-
setEditable
-
getSuggestion
-
setSuggestion
-
setSuggestion
-
setBackgroundPainter
-
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.
-
onCharTyped
@Environment(CLIENT) public void onCharTyped(char ch) 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
-
onKeyPressed
@Environment(CLIENT) public void onKeyPressed(int ch, int key, int modifiers) Description copied from class:WWidgetNotifies this widget that a key has been pressed.- Overrides:
onKeyPressedin classWWidgetkey- the GLFW scancode of the key
-
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
-
getCaretPos
From an X offset past the left edge of a TextRenderer.draw, finds out what the closest caret position (division between letters) is.- Parameters:
s-x-- Returns:
-
getCaretOffset
From a caret position, finds out what the x-offset to draw the caret is.- Parameters:
s-pos-- Returns:
-