Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TextFieldWidget extends BaseTextFieldWidget<TextFieldWidget> {

private IStringValue<?> stringValue;
private Function<String, String> validator = val -> val;
private boolean numbers = false;
private boolean isNumber = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why rename?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the name for a boolean is not explicit in my opinion. But i rollback if you want.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, roll this back. It just makes backporting commits harder.

private String mathFailMessage = null;
private double defaultNumber = 0;
private boolean tooltipOverride = false;
Expand All @@ -52,6 +52,7 @@ public double parse(String num) {
return 0.0;
}
}
num = num.replaceAll("\\D+", "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats this for?

Copy link
Author

@NeutronSelector NeutronSelector Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this : Improve QOL when a field is numric, remove all non numeric chars onRemoveFocus instead set 0.
Before, when user leave focus
1556e => is set to 0, test55test55 => 0
After
1556e => is set to 1556, test55test55 => 5555

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not desired behaviour. It will break expressions for example.

ParseResult result = MathUtils.parseExpression(num, this.defaultNumber, true);
if (result.isFailure()) {
this.mathFailMessage = result.getErrorMessage();
Expand Down Expand Up @@ -144,15 +145,15 @@ public void onRemoveFocus(ModularGuiContext context) {
} else {
throw new IllegalStateException("TextFieldWidget can only have one line!");
}
this.stringValue.setStringValue(this.numbers ? format.parse(getText(), new ParsePosition(0)).toString() : getText());
this.stringValue.setStringValue(this.isNumber ? format.parse(getText(), new ParsePosition(0)).toString() : getText());
}

@Override
protected void onTextChanged() {
super.onTextChanged();
if (this.autoUpdateOnChange) {
String text = this.validator.apply(getText());
this.stringValue.setStringValue(this.numbers ? format.parse(text, new ParsePosition(0)).toString() : getText());
this.stringValue.setStringValue(this.isNumber ? format.parse(text, new ParsePosition(0)).toString() : getText());
}
}

Expand Down Expand Up @@ -210,7 +211,7 @@ public TextFieldWidget setValidator(Function<String, String> validator) {
}

public TextFieldWidget setNumbersLong(Function<Long, Long> validator) {
this.numbers = true;
this.isNumber = true;
setValidator(val -> {
long num;
if (val.isEmpty()) {
Expand All @@ -224,7 +225,7 @@ public TextFieldWidget setNumbersLong(Function<Long, Long> validator) {
}

public TextFieldWidget setNumbers(Function<Integer, Integer> validator) {
this.numbers = true;
this.isNumber = true;
return setValidator(val -> {
int num;
if (val.isEmpty()) {
Expand All @@ -237,7 +238,7 @@ public TextFieldWidget setNumbers(Function<Integer, Integer> validator) {
}

public TextFieldWidget setNumbersDouble(Function<Double, Double> validator) {
this.numbers = true;
this.isNumber = true;
return setValidator(val -> {
double num;
if (val.isEmpty()) {
Expand Down Expand Up @@ -271,6 +272,9 @@ public TextFieldWidget setDefaultNumber(double defaultNumber) {
}

public TextFieldWidget setFormatAsInteger(boolean formatAsInteger) {
if (formatAsInteger && !this.isNumber) {
setNumbers(Integer.MIN_VALUE, Integer.MAX_VALUE);
}
this.renderer.setFormatAsInteger(formatAsInteger);
return getThis();
}
Expand All @@ -287,7 +291,7 @@ public TextFieldWidget value(IStringValue<?> stringValue) {
@Override
public boolean onMouseScroll(UpOrDown scrollDirection, int amount) {
// default to basic behavior if scroll step isn't on, if the widget is not using numbers, and if it is focused
if (!this.usingScrollStep || !this.numbers || !isFocused()) return super.onMouseScroll(scrollDirection, amount);
if (!this.usingScrollStep || !this.isNumber || !isFocused()) return super.onMouseScroll(scrollDirection, amount);

double value;
if (Interactable.hasControlDown()) value = scrollDirection.modifier * scrollStepCtrl;
Expand Down