[orx-panel] Add code that waits for a body ancestor to be connected in Textfield
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 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,17 +147,27 @@ fun Textfield.bind(property: KMutableProperty0<String>) {
|
|||||||
currentValue = it.newValue
|
currentValue = it.newValue
|
||||||
property.set(it.newValue)
|
property.set(it.newValue)
|
||||||
}
|
}
|
||||||
fun update() {
|
|
||||||
val cval = property.get()
|
GlobalScope.launch {
|
||||||
if (cval != currentValue) {
|
while (!disposed) {
|
||||||
currentValue = cval
|
val body = (root() as? Body)
|
||||||
value = cval
|
if (body != null) {
|
||||||
}
|
fun update() {
|
||||||
}
|
val cval = property.get()
|
||||||
update()
|
if (cval != currentValue) {
|
||||||
(root() as Body).controlManager.program.launch {
|
currentValue = cval
|
||||||
while (true) {
|
value = cval
|
||||||
update()
|
}
|
||||||
|
}
|
||||||
|
update()
|
||||||
|
(root() as Body).controlManager.program.launch {
|
||||||
|
while (true) {
|
||||||
|
update()
|
||||||
|
yield()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
yield()
|
yield()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user