fix: update slider text on value change
This commit is contained in:
parent
43e3bed0b2
commit
a5d12468ed
|
@ -1,9 +1,9 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl.ui.tiny.entry;
|
||||
|
||||
import io.gitlab.jfronny.commons.StringFormatter;
|
||||
import net.minecraft.client.gui.widget.SliderWidget;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CustomSlider extends SliderWidget {
|
||||
|
@ -38,6 +38,7 @@ public class CustomSlider extends SliderWidget {
|
|||
|
||||
public void setValue(double value) {
|
||||
this.value = rangeToSlider(value, min, max);
|
||||
updateMessage();
|
||||
}
|
||||
|
||||
private static double sliderToRange(double value, double min, double max) {
|
||||
|
@ -49,6 +50,6 @@ public class CustomSlider extends SliderWidget {
|
|||
}
|
||||
|
||||
private static Text toText(double value) {
|
||||
return Text.literal(Objects.toString(value));
|
||||
return Text.literal(StringFormatter.toString(value));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.gitlab.jfronny.libjf.config.api.v1.dsl.DSL;
|
|||
|
||||
public class TestConfig implements JfCustomConfig {
|
||||
private int value1 = 0;
|
||||
private double doubleValue = 0.3;
|
||||
private String value2 = "";
|
||||
private boolean value3 = false;
|
||||
private int value4 = 0;
|
||||
|
@ -16,6 +17,7 @@ public class TestConfig implements JfCustomConfig {
|
|||
dsl.register(builder -> builder
|
||||
.category("ca1", builder1 -> builder1
|
||||
.value("value1", value1, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, () -> value1, v -> value1 = v)
|
||||
.value("doubleValue", doubleValue, -0.74, 1.6, () -> doubleValue, v -> doubleValue = v)
|
||||
).category("ca2", builder1 -> builder1
|
||||
.value("value2", value2, () -> value2, v -> value2 = v)
|
||||
).category("ca3", builder1 -> builder1
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
{
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.title": "JfConfig example",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.title": "JfConfig Tiny Example",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.ca1.title": "Category 1",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.ca1.tooltip": "This is category 1\nIt has an excessively long description to test multiline descriptions and wrapping, which are required for this to look good.\nThis is supported btw.",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.ca1.value1": "Value 1",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.ca1.doubleValue": "Double Value",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.ca2.title": "Category 2",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.ca2.tooltip": "This is category 2",
|
||||
"libjf-config-ui-tiny-v1-testmod.jfconfig.ca2.value2": "Value 2",
|
||||
|
|
Loading…
Reference in New Issue