Skip to content
Merged
Show file tree
Hide file tree
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 @@ -180,13 +180,13 @@ private void intW(WTable table, IntSetting setting) {
}

private void longW(WTable table, LongSetting setting) {
WTextBox textBox = table.add(theme.textBox(setting.get().toString(), (text, c) -> Character.isDigit(c) || c == '-' && !text.contains("-"))).expandX().widget();
textBox.actionOnUnfocused = () -> {
setting.parse(textBox.get());
textBox.set(setting.get().toString());
WLongEdit edit = table.add(theme.longEdit(setting.get(), setting.min, setting.max)).expandX().widget();

edit.action = () -> {
if (!setting.set(edit.get())) edit.set(setting.get());
};

reset(table, setting, () -> textBox.set(setting.get().toString()));
reset(table, setting, () -> edit.set(setting.get()));
}

private void doubleW(WTable table, DoubleSetting setting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ public WIntEdit intEdit(int value, int min, int max, boolean noSlider) {
return w(new WIntEdit(value, min, max, 0, 0, noSlider));
}

public WLongEdit longEdit(long value, long min, long max) {
return w(new WLongEdit(value, min, max));
}

public WDoubleEdit doubleEdit(double value, double min, double max, double sliderMin, double sliderMax, int decimalPlaces, boolean noSlider) {
return w(new WDoubleEdit(value, min, max, sliderMin, sliderMax, decimalPlaces, noSlider));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

package meteordevelopment.meteorclient.gui.widgets.input;

import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList;

public class WLongEdit extends WHorizontalList {
private long value;

public final long min, max;
public Runnable action;

private WTextBox textBox;

public WLongEdit(long value, long min, long max) {
this.value = value;
this.min = min;
this.max = max;
}

@Override
public void init() {
textBox = add(theme.textBox(Long.toString(value), (text, c) -> Character.isDigit(c) || c == '-' && !text.contains("-"))).minWidth(75).expandX().widget();

textBox.actionOnUnfocused = () -> {
long lastValue = value;

try {
long parsed = Long.parseLong(textBox.get().trim());
if (parsed >= min && parsed <= max) value = parsed;
} catch (NumberFormatException _) {}

textBox.set(Long.toString(value));

if (action != null && value != lastValue) action.run();
};
}

public long get() {
return value;
}

public void set(long value) {
this.value = value;
textBox.set(Long.toString(value));
}
}
Loading