Some fixes for floating point formatting
This commit is contained in:
parent
ef38a9888b
commit
5637de6ac6
2 changed files with 23 additions and 2 deletions
|
@ -26,7 +26,7 @@ public class TestScreen extends Screen {
|
||||||
VerticalStack<?> rows = new VerticalStack<>(DynamicSize.fit(), DynamicSize.relative(1));
|
VerticalStack<?> rows = new VerticalStack<>(DynamicSize.fit(), DynamicSize.relative(1));
|
||||||
|
|
||||||
rows.addFiller();
|
rows.addFiller();
|
||||||
rows.add(new Range<Integer>(
|
rows.add(new Range<>(
|
||||||
DynamicSize.fill(), DynamicSize.fit(),
|
DynamicSize.fill(), DynamicSize.fit(),
|
||||||
Component.literal("Integer"),
|
Component.literal("Integer"),
|
||||||
10, 90, 20,
|
10, 90, 20,
|
||||||
|
@ -35,6 +35,15 @@ public class TestScreen extends Screen {
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
rows.addSpacer(8);
|
rows.addSpacer(8);
|
||||||
|
rows.add(new Range<>(
|
||||||
|
DynamicSize.fill(), DynamicSize.fit(),
|
||||||
|
Component.literal("Float"),
|
||||||
|
10f, 90f, 20f,
|
||||||
|
(slider, value) -> {
|
||||||
|
System.out.println(value);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
rows.addSpacer(16);
|
||||||
rows.add(new Button(
|
rows.add(new Button(
|
||||||
DynamicSize.fit(), DynamicSize.fit(),
|
DynamicSize.fit(), DynamicSize.fit(),
|
||||||
Component.literal("test"),
|
Component.literal("test"),
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class Slider<N extends Number> extends AbstractSliderButton {
|
||||||
this.minValue = minValue;
|
this.minValue = minValue;
|
||||||
this.maxValue = maxValue;
|
this.maxValue = maxValue;
|
||||||
this.onChange = onChange;
|
this.onChange = onChange;
|
||||||
|
|
||||||
this.updateMessage();
|
this.updateMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,18 @@ public class Slider<N extends Number> extends AbstractSliderButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String valueToString(N value) {
|
protected String valueToString(N value) {
|
||||||
|
if (minValue instanceof Float || minValue instanceof Double) {
|
||||||
|
double v = value.doubleValue();
|
||||||
|
double m = maxValue.doubleValue();
|
||||||
|
if (m > 1000)
|
||||||
|
return "" + (int) v;
|
||||||
|
if (m > 100)
|
||||||
|
return String.format("%.1f", v);
|
||||||
|
if (m > 10)
|
||||||
|
return String.format("%.2f", v);
|
||||||
|
|
||||||
|
return String.format("%.4f", v);
|
||||||
|
}
|
||||||
return "" + value;
|
return "" + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue