[orx-panel] Fix Textfield.bind
This commit is contained in:
@@ -12,7 +12,9 @@ import org.openrndr.KEY_ARROW_UP
|
||||
import org.openrndr.KEY_ENTER
|
||||
import org.openrndr.events.Event
|
||||
import org.openrndr.launch
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
|
||||
class Item : Element(ElementType("item")) {
|
||||
@@ -122,7 +124,7 @@ class DropdownButton : Element(ElementType("dropdown-button")), DisposableElemen
|
||||
val textHeight = font.ascenderLength
|
||||
|
||||
val offset = Math.round((layout.screenWidth - textWidth))
|
||||
val yOffset = Math.round((layout.screenHeight / 2) + textHeight / 2.0) - 2.0
|
||||
val yOffset = ((layout.screenHeight / 2) + textHeight / 2.0).roundToInt() - 2.0
|
||||
|
||||
drawer.fill = ((computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE)
|
||||
|
||||
@@ -155,8 +157,8 @@ class DropdownButton : Element(ElementType("dropdown-button")), DisposableElemen
|
||||
it.cancelPropagation()
|
||||
val newValue = parent.items()[activeIndex]
|
||||
|
||||
parent.value?.let {
|
||||
itemButtons[it]?.pseudoClasses?.remove(ElementPseudoClass("selected"))
|
||||
parent.value?.let { item ->
|
||||
itemButtons[item]?.pseudoClasses?.remove(ElementPseudoClass("selected"))
|
||||
}
|
||||
parent.value?.let {
|
||||
itemButtons[newValue]?.pseudoClasses?.add(ElementPseudoClass("selected"))
|
||||
@@ -185,8 +187,8 @@ class DropdownButton : Element(ElementType("dropdown-button")), DisposableElemen
|
||||
scrollTop -= 24.0
|
||||
}
|
||||
|
||||
parent.value?.let {
|
||||
itemButtons[it]?.pseudoClasses?.remove(ElementPseudoClass("selected"))
|
||||
parent.value?.let { item ->
|
||||
itemButtons[item]?.pseudoClasses?.remove(ElementPseudoClass("selected"))
|
||||
}
|
||||
parent.value?.let {
|
||||
itemButtons[newValue]?.pseudoClasses?.add(ElementPseudoClass("selected"))
|
||||
@@ -201,7 +203,7 @@ class DropdownButton : Element(ElementType("dropdown-button")), DisposableElemen
|
||||
|
||||
mouse.scrolled.listen {
|
||||
scrollTop -= it.rotation.y
|
||||
scrollTop = Math.max(0.0, scrollTop)
|
||||
scrollTop = max(0.0, scrollTop)
|
||||
draw.dirty = true
|
||||
it.cancelPropagation()
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class Textfield : Element(ElementType("textfield")), DisposableElement {
|
||||
val yOffset = Math.round((layout.screenHeight / 2) + textHeight / 2.0 - 2.0) * 1.0
|
||||
|
||||
drawer.fill = ((computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE)
|
||||
drawer.text("$label", 0.0 + offset, 0.0 + yOffset - textHeight * 1.5)
|
||||
drawer.text(label, 0.0 + offset, 0.0 + yOffset - textHeight * 1.5)
|
||||
|
||||
drawer.fill = (((computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE).opacify(0.05))
|
||||
drawer.rectangle(0.0 + offset, 0.0 + yOffset - (textHeight + 2), layout.screenWidth - 10.0, textHeight + 8.0)
|
||||
@@ -132,41 +132,34 @@ class Textfield : Element(ElementType("textfield")), DisposableElement {
|
||||
|
||||
drawer.stroke = computedStyle.effectiveColor?.shade(0.25)
|
||||
drawer.lineCap = LineCap.ROUND
|
||||
//drawer.lineSegment(0.0, yOffset + 4.0, layout.screenWidth, yOffset + 4.0)
|
||||
}
|
||||
}
|
||||
|
||||
override var disposed: Boolean = false
|
||||
|
||||
}
|
||||
|
||||
fun Textfield.bind(property: KMutableProperty0<String>) {
|
||||
var currentValue = property.get()
|
||||
|
||||
events.valueChanged.listen {
|
||||
currentValue = it.newValue
|
||||
property.set(it.newValue)
|
||||
}
|
||||
|
||||
GlobalScope.launch {
|
||||
while (!disposed) {
|
||||
install@ while (!disposed) {
|
||||
val body = (root() as? Body)
|
||||
if (body != null) {
|
||||
events.valueChanged.listen {
|
||||
property.set(it.newValue)
|
||||
}
|
||||
fun update() {
|
||||
val cval = property.get()
|
||||
if (cval != currentValue) {
|
||||
currentValue = cval
|
||||
value = cval
|
||||
val propertyValue = property.get()
|
||||
if (propertyValue != value) {
|
||||
value = propertyValue
|
||||
}
|
||||
}
|
||||
update()
|
||||
(root() as Body).controlManager.program.launch {
|
||||
while (true) {
|
||||
while (!disposed) {
|
||||
update()
|
||||
yield()
|
||||
}
|
||||
}
|
||||
break
|
||||
break@install
|
||||
}
|
||||
yield()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user