[orx-panel] Add code that waits for a body ancestor to be connected in Slider/Toggle.bind
This commit is contained in:
@@ -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<Double>) {
|
||||
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<Int>) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Boolean>) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user