From 6a0455cfaff24c15f32a1c523486dc2458917ec8 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Thu, 7 May 2020 14:13:19 +0200 Subject: [PATCH] Add Slider to Int property binding --- .../org/openrndr/panel/elements/Slider.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt index 95d67e20..fad971f5 100644 --- a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt +++ b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Slider.kt @@ -254,3 +254,26 @@ fun Slider.bind(property: KMutableProperty0) { } } } + +@JvmName("bindInt") +fun Slider.bind(property: KMutableProperty0) { + var currentValue: Int? = null + + events.valueChanged.listen { + currentValue = it.newValue.toInt() + property.set(it.newValue.toInt()) + } + if (root() as? Body == null) { + throw RuntimeException("no body") + } + (root() as? Body)?.controlManager?.program?.launch { + while (true) { + if (property.get()!= currentValue) { + val lcur = property.get() + currentValue = lcur + value = lcur.toDouble() + } + yield() + } + } +}