Class TextInputComponent
Single-line editable text field component.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a text input with sensible default styling and size. -
Method Summary
Modifier and TypeMethodDescriptionaddValidator(Predicate<String> validator) Adds an additional validator used for live text edits.booleanappend(char value) Appends a single character at the end of the field and runs the live transform/validation pipeline.booleanAppends text at the end of the field and runs the live transform/validation pipeline.Sets the font used to render the input text.protected booleanhandlesMouseClick(float mouseX, float mouseY, int button) protected booleanintlength()Returns the current character count.letterSpacing(float pixels) lineHeight(float multiplier) maxLength(int maxLength) Sets the maximum number of characters the field may contain.Sets a callback invoked when the field loses focus.Sets a callback invoked whenever the field value changes.protected booleanonCharTyped(com.render.api.gui.GuiRenderContext context, int codePoint, int modifiers) protected voidonFocusChanged(boolean focused) protected booleanonKeyPressed(com.render.api.gui.GuiRenderContext context, int keyCode, int scanCode, int modifiers) protected booleanonMouseClicked(com.render.api.gui.GuiRenderContext context, float mouseX, float mouseY, int button) protected booleanonMouseDragged(com.render.api.gui.GuiRenderContext context, float mouseX, float mouseY, int button, double dragX, double dragY) protected booleanonMouseReleased(com.render.api.gui.GuiRenderContext context, float mouseX, float mouseY, int button) Sets a callback invoked when the user submits the field with Enter.placeholder(String placeholder) Sets placeholder text shown while the value is empty.placeholder(net.minecraft.network.chat.Component placeholder) Sets placeholder text shown while the value is empty.protected voidrenderSelf(com.render.api.gui.GuiRenderContext context) shadow(boolean shadow) Enables or disables the standard text shadow.textScalePixels(float pixels) Sets the text size in design-space pixels.textStyle(GuiTextStyle style) textTransformer(UnaryOperator<String> transformer) Sets a live text transformer applied to every attempted edit before validation.protected voidtick()Replaces the current validator used for live text edits.value()Returns the current field value.Replaces the current value.Methods inherited from class GuiComponent
activeStateStyle, add, alignContent, alignItems, alignSelf, anchor, anchorName, anchorPlacement, animatedBorder, animation, applyStyle, aspectRatio, autoHeight, autoSize, autoWidth, backdropFilters, backfaceVisibility, backgroundColor, backgroundColor, backgroundLayer, backgroundLayers, backgroundLayers, border, borderCollapse, borderColor, borderColor, borderSpacing, borderWidth, boxDecorationBreak, boxGlow, boxShadow, boxShadows, boxShadows, boxSizing, breakAfter, breakBefore, breakInside, cancel, captionSide, caretStyle, centered, childGap, childLayout, childLayoutViewport, childOffsetX, childOffsetY, children, clearChildren, clipChildren, clipPath, clipsChildren, color, color, columnCount, columnFill, columnGap, columnRule, columnSpan, columnWidth, computedStyle, containsChildClipPoint, contextMenu, cornerRadius, defaultDisplay, dirtyCategories, disabled, display, emptyCells, enabled, enabled, filters, findById, findById, flexBasis, flexDirection, flexGrow, flexShrink, flexWrap, focused, focused, fragmentTree, glow, gradient, gridAutoFlow, gridPlacement, gridTemplate, handlesMouseScroll, height, height, height, hovered, id, id, indeterminate, indeterminate, inlineStyle, inset, inset, intrinsicSize, invalidateModernLayout, isClippingChildren, justifyContent, justifyItems, justifySelf, lastInvalidationReason, layoutChildren, layoutFragments, listStyleImage, listStylePosition, listStyleType, margin, margin, margin, marginBreak, markerGap, markerSide, maskLayers, maskLayers, matchesStyleState, maxHeight, maxWidth, minHeight, minWidth, motionPath, onModernLayoutComplete, onMouseScrolled, opacity, order, orphans, outline, padding, padding, padding, pageName, paint, parent, pause, play, position, position, preferredHeight, preferredHeightForWidth, preferredWidth, pressed, pseudoElementBox, pseudoElementStyle, quotes, rangeState, rangeState, readOnly, readOnly, remove, removeStyleClass, renderChildren, renderClippedChildren, renderOverlay, requestFocus, required, required, resolveBaseProperties, resume, rowGap, scrollMargin, scrollMargin, scrollSnapStop, self, shadow, shouldRouteToChildren, size, size, startingStyle, stateProvider, styleAttribute, styleAttribute, styleClass, styleClasses, styledPseudoElements, styleOpen, styleState, styleState, tabIndex, tabIndex, tableLayout, tooltip, transform, transformBox, transformOrigin, transformStyle, transition, transition, transition, transition, transition, transition, transitionAll, transitionAll, transitionAll, translate, translateX, translateY, validity, validity, verticalAlign, viewTransitionName, viewTransitionName, visible, visible, widows, width, width, width, writeModernInline, writeTextShadow, writingState, x, x, y, y, zIndex
-
Constructor Details
-
TextInputComponent
public TextInputComponent()Creates a text input with sensible default styling and size.
-
-
Method Details
-
value
Replaces the current value.- Parameters:
value- new field value- Returns:
- this component
-
value
-
placeholder
Sets placeholder text shown while the value is empty.- Parameters:
placeholder- literal placeholder text- Returns:
- this component
-
placeholder
Sets placeholder text shown while the value is empty.- Parameters:
placeholder- rich text placeholder- Returns:
- this component
-
font
Sets the font used to render the input text.- Parameters:
font- font configuration- Returns:
- this component
-
textStyle
-
textScalePixels
Sets the text size in design-space pixels.- Parameters:
pixels- text size- Returns:
- this component
-
letterSpacing
-
lineHeight
-
shadow
Enables or disables the standard text shadow.- Parameters:
shadow-trueto render the vanilla-style text shadow- Returns:
- this component
-
maxLength
Sets the maximum number of characters the field may contain.- Parameters:
maxLength- maximum character count- Returns:
- this component
-
textTransformer
Sets a live text transformer applied to every attempted edit before validation.- Parameters:
transformer- text transformer- Returns:
- this component
-
validator
Replaces the current validator used for live text edits.- Parameters:
validator- validator for the full candidate text- Returns:
- this component
-
addValidator
Adds an additional validator used for live text edits.- Parameters:
validator- validator for the full candidate text- Returns:
- this component
-
append
Appends text at the end of the field and runs the live transform/validation pipeline.- Parameters:
value- text to append- Returns:
trueif the value changed
-
append
public boolean append(char value) Appends a single character at the end of the field and runs the live transform/validation pipeline.- Parameters:
value- character to append- Returns:
trueif the value changed
-
length
public int length()Returns the current character count.- Returns:
- current text length
-
onChange
Sets a callback invoked whenever the field value changes.- Parameters:
onChange- value-change callback- Returns:
- this component
-
onSubmit
Sets a callback invoked when the user submits the field with Enter.- Parameters:
onSubmit- submit callback- Returns:
- this component
-
onBlur
Sets a callback invoked when the field loses focus.- Parameters:
onBlur- blur callback- Returns:
- this component
-
isFocusable
protected boolean isFocusable()- Overrides:
isFocusablein classGuiComponent<TextInputComponent>
-
handlesMouseClick
protected boolean handlesMouseClick(float mouseX, float mouseY, int button) - Overrides:
handlesMouseClickin classGuiComponent<TextInputComponent>
-
onMouseClicked
protected boolean onMouseClicked(com.render.api.gui.GuiRenderContext context, float mouseX, float mouseY, int button) - Overrides:
onMouseClickedin classGuiComponent<TextInputComponent>
-
onMouseDragged
protected boolean onMouseDragged(com.render.api.gui.GuiRenderContext context, float mouseX, float mouseY, int button, double dragX, double dragY) - Overrides:
onMouseDraggedin classGuiComponent<TextInputComponent>
-
onMouseReleased
protected boolean onMouseReleased(com.render.api.gui.GuiRenderContext context, float mouseX, float mouseY, int button) - Overrides:
onMouseReleasedin classGuiComponent<TextInputComponent>
-
onKeyPressed
protected boolean onKeyPressed(com.render.api.gui.GuiRenderContext context, int keyCode, int scanCode, int modifiers) - Overrides:
onKeyPressedin classGuiComponent<TextInputComponent>
-
onCharTyped
protected boolean onCharTyped(com.render.api.gui.GuiRenderContext context, int codePoint, int modifiers) - Overrides:
onCharTypedin classGuiComponent<TextInputComponent>
-
onFocusChanged
protected void onFocusChanged(boolean focused) - Overrides:
onFocusChangedin classGuiComponent<TextInputComponent>
-
tick
protected void tick()- Overrides:
tickin classGuiComponent<TextInputComponent>
-
renderSelf
protected void renderSelf(com.render.api.gui.GuiRenderContext context) - Overrides:
renderSelfin classGuiComponent<TextInputComponent>
-