Skip to content

Commit a2c3264

Browse files
authored
Show decimals on range sliders with low bounds (#931)
1 parent d8cabe8 commit a2c3264

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ui/src/main/java/edu/wpi/grip/ui/pipeline/input/RangeInputSocketController.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,19 @@ public void initialize() {
101101
}
102102

103103
private String getLowHighLabelText() {
104-
return String.format("%.0f - %.0f", this.slider.getLowValue(), this.slider.getHighValue());
104+
// Ensure that we use the same number of decimal places for both the low and high values
105+
// Otherwise we could have something like "0.01 - 123" instead of "0 - 123"
106+
int max = (int) Math.max(Math.abs(this.slider.getMin()), Math.abs(this.slider.getMax()));
107+
int numDecimals;
108+
if (max >= 100) {
109+
numDecimals = 0;
110+
} else if (max >= 10) {
111+
numDecimals = 1;
112+
} else {
113+
numDecimals = 2;
114+
}
115+
String fmt = "%." + numDecimals + "f";
116+
return String.format(fmt + " - " + fmt, this.slider.getLowValue(), this.slider.getHighValue());
105117
}
106118

107119
@Subscribe

0 commit comments

Comments
 (0)