[orx-panel] Add code that waits for a body ancestor to be connected in Textfield

This commit is contained in:
Edwin Jakobs
2020-07-10 12:04:16 +02:00
parent f0ddc9339f
commit b050c52621

View File

@@ -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.KEY_BACKSPACE import org.openrndr.KEY_BACKSPACE
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.Drawer import org.openrndr.draw.Drawer
@@ -14,7 +16,7 @@ import org.openrndr.text.Cursor
import org.openrndr.text.writer import org.openrndr.text.writer
import kotlin.reflect.KMutableProperty0 import kotlin.reflect.KMutableProperty0
class Textfield : Element(ElementType("textfield")) { class Textfield : Element(ElementType("textfield")), DisposableElement {
var value: String = "" var value: String = ""
var label: String = "label" var label: String = "label"
@@ -133,6 +135,9 @@ class Textfield : Element(ElementType("textfield")) {
//drawer.lineSegment(0.0, yOffset + 4.0, layout.screenWidth, yOffset + 4.0) //drawer.lineSegment(0.0, yOffset + 4.0, layout.screenWidth, yOffset + 4.0)
} }
} }
override var disposed: Boolean = false
} }
fun Textfield.bind(property: KMutableProperty0<String>) { fun Textfield.bind(property: KMutableProperty0<String>) {
@@ -142,6 +147,11 @@ fun Textfield.bind(property: KMutableProperty0<String>) {
currentValue = it.newValue currentValue = it.newValue
property.set(it.newValue) property.set(it.newValue)
} }
GlobalScope.launch {
while (!disposed) {
val body = (root() as? Body)
if (body != null) {
fun update() { fun update() {
val cval = property.get() val cval = property.get()
if (cval != currentValue) { if (cval != currentValue) {
@@ -156,4 +166,9 @@ fun Textfield.bind(property: KMutableProperty0<String>) {
yield() yield()
} }
} }
break
}
yield()
}
}
} }