Skip to content

TextFieldWidget

The TextFieldWidget provides an editable text field for GUI interfaces. It supports dynamic text updates via a supplier and responder, validation through custom validators, and configurable properties such as maximum string length, border style, and text color.

Basic Properties

FieldDescription
currentStringThe current text displayed by the text field
maxStringLengthMaximum allowed length for the text
isBorderedDetermines whether the text field has a border
textColorThe color of the text (modifiable via setter)
supplierA supplier for dynamic text updates
textResponderA responder that handles text changes
wheelDurDuration (or step value) used for mouse wheel adjustments

APIs

setTextSupplier

Sets the supplier used to update the text dynamically.

java
textFieldWidget.setTextSupplier(() -> "Dynamic Text");

setTextResponder

Sets the responder to be called when the text changes.

java
textFieldWidget.setTextResponder(newText -> {
    // Handle text change
});

setBordered

Configures whether the text field should display a border.

java
textFieldWidget.setBordered(true);

setTextColor

Sets the text color for the text field.

java
textFieldWidget.setTextColor(0xffffff);

setMaxStringLength

Sets the maximum number of characters allowed in the text field.

java
textFieldWidget.setMaxStringLength(100);

setValidator

Assigns a custom validator function to control and sanitize text input.

java
textFieldWidget.setValidator(text -> text.trim());

setCompoundTagOnly

Restricts input to valid compound tags. Displays a tooltip indicating the restriction.

java
textFieldWidget.setCompoundTagOnly();

setResourceLocationOnly

Restricts input to valid resource locations. Displays a tooltip indicating the restriction.

java
textFieldWidget.setResourceLocationOnly();

setNumbersOnly

Restricts input to numeric values. Overloads are available for different numeric types.

java
textFieldWidget.setNumbersOnly(0, 100); // int
textFieldWidget.setNumbersOnly(0.0f, 1.0f); // float

setWheelDur

Sets the wheel duration (step value) for adjusting numbers via mouse wheel or dragging.

java
textFieldWidget.setWheelDur(1);

Released under the MIT License.