From d9e28fc88613d89c7248fea2f4a686aae0944bea Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Sun, 2 Feb 2020 23:01:23 +0100 Subject: [PATCH] Add ui generator for ColorParameter --- orx-gui/src/main/kotlin/Gui.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/orx-gui/src/main/kotlin/Gui.kt b/orx-gui/src/main/kotlin/Gui.kt index 895e0ec1..9fbd33aa 100644 --- a/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-gui/src/main/kotlin/Gui.kt @@ -39,6 +39,10 @@ class GUI : Extension { this.marginRight = 2.px this.height = 100.percent this.background = Color.RGBa(ColorRGBa.GRAY.copy(a = 0.2)) + + descendant(has type "colorpicker-button") { + this.width = 175.px + } } styleSheet(has type "dropdown-button") { @@ -77,7 +81,7 @@ class GUI : Extension { private fun Div.addControl(obj: Any, parameter: Parameter) { - when(val type = parameter.parameterType) { + when(parameter.parameterType) { ParameterType.Int -> { slider { label = parameter.label @@ -138,6 +142,17 @@ class GUI : Extension { } } } + + ParameterType.Color -> { + colorpickerButton { + label = parameter.label + color = (parameter.property as KMutableProperty1).get(obj) + events.valueChanged.subscribe { + (parameter.property as KMutableProperty1).set(obj, it.color) + onChangeListener?.invoke(parameter.property.name, it.color) + } + } + } } }