Hi everyone,
I have the following code to setup a Slider, pay attention to the default value 33.50 and the range going from 0.0 to 100.0:
extend(ControlManager()) {
layout {
slider {
label = "Slide me"
value = 33.50
range = Range(0.0, 100.0)
precision = 2
events.valueChanged.listen {
println("the new value is ${it.newValue}")
}
}
}
}
The slider works correctly once you actually move it for the first time, but before interacting with it, as you can see in the image, the value according the text is 10.0 and the slider location corresponds with that incorrect value as well.
It seems that unless you move the slider then the value gets clamped to the range inside the Slider class (0.0 to 10.0) and not to the range specified in the code shown before. You have to move it first and then it works correctly.
Here is the Slider class snippet and I think it’s probably due to the cleaning of the variable:
var range = Range(0.0, 10.0)
set(value) {
field = value
this.value = this.value
}
...
fun clean(value: Double): Double {
val cleanV = value.coerceIn(range.min, range.max)
val quantized = String.format("%.0${precision}f", cleanV).replace(",", ".").toDouble()
return quantized
}
Please let me know if you understand the issue as I described it, and I hope I got it right. If not, my apologies for any confusion. I’m not really an expert in this, so I’m not sure how to reference the values I received during initialization. That’s why I haven’t tried making a pull request yet. But hey, if everything seems good and someone could walk me through the process, I’d be happy to give it a shot and make my first contribution to the project.
Best regards.