[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
|
package org.openrndr.panel.elements
|
||||||
|
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import org.openrndr.*
|
import org.openrndr.*
|
||||||
@@ -296,25 +298,29 @@ fun Slider.bind(property: KMutableProperty0<Double>) {
|
|||||||
currentValue = it.newValue
|
currentValue = it.newValue
|
||||||
property.set(it.newValue)
|
property.set(it.newValue)
|
||||||
}
|
}
|
||||||
if (root() as? Body == null) {
|
GlobalScope.launch {
|
||||||
throw RuntimeException("no body")
|
while(!disposed) {
|
||||||
}
|
val body = (root() as? Body)
|
||||||
|
if (body != null) {
|
||||||
fun update() {
|
fun update() {
|
||||||
if (property.get() != currentValue) {
|
if (property.get() != currentValue) {
|
||||||
val lcur = property.get()
|
val lcur = property.get()
|
||||||
currentValue = lcur
|
currentValue = lcur
|
||||||
value = lcur
|
value = lcur.toDouble()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update()
|
update()
|
||||||
|
body.controlManager.program.launch {
|
||||||
(root() as? Body)?.controlManager?.program?.launch {
|
|
||||||
while (!disposed) {
|
while (!disposed) {
|
||||||
update()
|
update()
|
||||||
yield()
|
yield()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
yield()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmName("bindInt")
|
@JvmName("bindInt")
|
||||||
@@ -324,9 +330,10 @@ fun Slider.bind(property: KMutableProperty0<Int>) {
|
|||||||
currentValue = it.newValue.toInt()
|
currentValue = it.newValue.toInt()
|
||||||
property.set(it.newValue.toInt())
|
property.set(it.newValue.toInt())
|
||||||
}
|
}
|
||||||
if (root() as? Body == null) {
|
GlobalScope.launch {
|
||||||
throw RuntimeException("no body")
|
while(!disposed) {
|
||||||
}
|
val body = (root() as? Body)
|
||||||
|
if (body != null) {
|
||||||
fun update() {
|
fun update() {
|
||||||
if (property.get() != currentValue) {
|
if (property.get() != currentValue) {
|
||||||
val lcur = property.get()
|
val lcur = property.get()
|
||||||
@@ -335,10 +342,15 @@ fun Slider.bind(property: KMutableProperty0<Int>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
update()
|
update()
|
||||||
(root() as? Body)?.controlManager?.program?.launch {
|
body.controlManager.program.launch {
|
||||||
while (!disposed) {
|
while (!disposed) {
|
||||||
update()
|
update()
|
||||||
yield()
|
yield()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
yield()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.openrndr.panel.elements
|
package org.openrndr.panel.elements
|
||||||
|
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.openrndr.draw.Drawer
|
import org.openrndr.draw.Drawer
|
||||||
import org.openrndr.draw.FontImageMap
|
import org.openrndr.draw.FontImageMap
|
||||||
import org.openrndr.draw.LineCap
|
import org.openrndr.draw.LineCap
|
||||||
@@ -106,9 +108,10 @@ 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) {
|
GlobalScope.launch {
|
||||||
throw RuntimeException("no body")
|
while (!disposed) {
|
||||||
}
|
val body = (root() as? Body)
|
||||||
|
if (body != null) {
|
||||||
fun update() {
|
fun update() {
|
||||||
if (property.get() != currentValue) {
|
if (property.get() != currentValue) {
|
||||||
val lcur = property.get()
|
val lcur = property.get()
|
||||||
@@ -123,4 +126,8 @@ fun Toggle.bind(property: KMutableProperty0<Boolean>) {
|
|||||||
yield()
|
yield()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user