[orx-toggle] Fix bind for Toggle

This commit is contained in:
edwin
2020-06-19 19:32:52 +02:00
parent 15f07fdfcd
commit b9401e03d3

View File

@@ -106,14 +106,20 @@ fun Toggle.bind(property: KMutableProperty0<Boolean>) {
currentValue = it.newValue currentValue = it.newValue
property.set(it.newValue) property.set(it.newValue)
} }
if (root() as? Body == null) {
throw RuntimeException("no body")
}
fun update() {
if (property.get() != currentValue) {
val lcur = property.get()
currentValue = lcur
value = lcur
}
}
update()
(root() as Body).controlManager.program.launch { (root() as Body).controlManager.program.launch {
while (!disposed) { while (!disposed) {
val cval = property.get() update()
if (cval != currentValue) {
currentValue = cval
value = cval
}
yield() yield()
} }
} }