diff --git a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt index 6cb6956b..0e8c56a5 100644 --- a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt +++ b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt @@ -1,5 +1,7 @@ package org.openrndr.panel.elements +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import kotlinx.coroutines.yield import mu.KotlinLogging import org.openrndr.* @@ -296,22 +298,26 @@ fun Slider.bind(property: KMutableProperty0) { currentValue = 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 { - while (!disposed) { - update() + GlobalScope.launch { + while(!disposed) { + val body = (root() as? Body) + if (body != null) { + fun update() { + if (property.get() != currentValue) { + val lcur = property.get() + currentValue = lcur + value = lcur.toDouble() + } + } + update() + body.controlManager.program.launch { + while (!disposed) { + update() + yield() + } + } + break + } yield() } } @@ -324,20 +330,26 @@ fun Slider.bind(property: KMutableProperty0) { currentValue = it.newValue.toInt() property.set(it.newValue.toInt()) } - if (root() as? Body == null) { - throw RuntimeException("no body") - } - fun update() { - if (property.get() != currentValue) { - val lcur = property.get() - currentValue = lcur - value = lcur.toDouble() - } - } - update() - (root() as? Body)?.controlManager?.program?.launch { - while (!disposed) { - update() + GlobalScope.launch { + while(!disposed) { + val body = (root() as? Body) + if (body != null) { + fun update() { + if (property.get() != currentValue) { + val lcur = property.get() + currentValue = lcur + value = lcur.toDouble() + } + } + update() + body.controlManager.program.launch { + while (!disposed) { + update() + yield() + } + } + break + } yield() } } diff --git a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt index df849f94..569bc4bf 100644 --- a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt +++ b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt @@ -1,5 +1,7 @@ package org.openrndr.panel.elements +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import org.openrndr.draw.Drawer import org.openrndr.draw.FontImageMap import org.openrndr.draw.LineCap @@ -106,21 +108,26 @@ fun Toggle.bind(property: KMutableProperty0) { currentValue = 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 { + GlobalScope.launch { while (!disposed) { - update() - yield() + val body = (root() as? Body) + if (body != null) { + fun update() { + if (property.get() != currentValue) { + val lcur = property.get() + currentValue = lcur + value = lcur + } + } + update() + (root() as Body).controlManager.program.launch { + while (!disposed) { + update() + yield() + } + } + break + } } } } \ No newline at end of file