Add Slider to Int property binding

This commit is contained in:
Edwin Jakobs
2020-05-07 14:13:19 +02:00
parent 0e3a1b4a4a
commit 6a0455cfaf

View File

@@ -254,3 +254,26 @@ fun Slider.bind(property: KMutableProperty0<Double>) {
}
}
}
@JvmName("bindInt")
fun Slider.bind(property: KMutableProperty0<Int>) {
var currentValue: Int? = null
events.valueChanged.listen {
currentValue = it.newValue.toInt()
property.set(it.newValue.toInt())
}
if (root() as? Body == null) {
throw RuntimeException("no body")
}
(root() as? Body)?.controlManager?.program?.launch {
while (true) {
if (property.get()!= currentValue) {
val lcur = property.get()
currentValue = lcur
value = lcur.toDouble()
}
yield()
}
}
}