Temporary property editor

This commit is contained in:
Alexander Nozik 2019-10-02 22:02:26 +03:00
parent d1e2d8d60b
commit 39ca362aa8
5 changed files with 39 additions and 16 deletions

View File

@ -18,6 +18,7 @@ allprojects {
jcenter()
maven("https://kotlin.bintray.com/kotlinx")
maven("https://kotlin.bintray.com/js-externals")
maven("https://kotlin.bintray.com/kotlin-js-wrappers")
maven("https://dl.bintray.com/pdvrieze/maven")
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}

View File

@ -34,6 +34,8 @@ kotlin {
implementation(npm("inspire-tree","6.0.1"))
implementation(npm("inspire-tree-dom","4.0.6"))
implementation(npm("jsoneditor"))
// api("org.jetbrains:kotlin-extensions:1.0.1-pre.83-kotlin-1.3.50")
// api(npm("core-js"))
}
}
}

View File

@ -110,6 +110,12 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
}
}
val VisualObject.prototype: VisualObject? get() = when(this){
is Proxy -> prototype
is Proxy.ProxyChild -> prototype
else -> null
}
inline fun VisualGroup3D.ref(
templateName: Name,
name: String = "",

View File

@ -113,8 +113,8 @@ var VisualObject.material: Meta?
get() = getProperty(MATERIAL_KEY).node
set(value) = setProperty(MATERIAL_KEY, value)
var VisualObject.opacity: Double
get() = getProperty(OPACITY_KEY).double ?: 1.0
var VisualObject.opacity: Double?
get() = getProperty(OPACITY_KEY).double
set(value) {
setProperty(OPACITY_KEY, value)
}

View File

@ -1,10 +1,16 @@
package hep.dataforge.vis.spatial.tree
import hep.dataforge.io.toJson
import hep.dataforge.meta.DynamicMeta
import hep.dataforge.meta.builder
import hep.dataforge.meta.update
import hep.dataforge.vis.common.VisualObject
import hep.dataforge.vis.spatial.Proxy
import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
import hep.dataforge.vis.spatial.color
import hep.dataforge.vis.spatial.opacity
import hep.dataforge.vis.spatial.prototype
import hep.dataforge.vis.spatial.visible
import kotlinx.html.InputType
import kotlinx.html.dom.append
@ -18,7 +24,9 @@ fun Element.propertyEditor(item: VisualObject?, name: String?) {
append {
div("card") {
div("card-body") {
h3(classes = "card-title") { +(name ?: "") }
h3(classes = "card-title") {
+(name ?: "")
}
form {
div("form-group row") {
label("col-form-label col-4") {
@ -64,18 +72,24 @@ fun Element.propertyEditor(item: VisualObject?, name: String?) {
}
}
}
(item.properties ?: (item as? Proxy)?.prototype?.properties
?: (item as? Proxy.ProxyChild)?.prototype?.properties)
?.let { config ->
(item.properties ?: item.prototype?.properties)?.let { config ->
div("card") {
div("card-body") {
h3(classes = "card-title") { +"Properties" }
}.apply {
val options = (js("{}") as JSONEditorOptions).apply {
mode = "view"
val metaToEdit = config.builder().apply {
VISIBLE_KEY to (item.visible ?: true)
COLOR_KEY to (item.color ?: "#ffffff")
OPACITY_KEY to (item.opacity ?: 1.0)
}
JSONEditor(this, options, JSON.parse(config.toJson().toString()))
//FIXME something rotten in JS-Meta converter
val jsObject: dynamic = JSON.parse(metaToEdit.toJson().toString())
//jsObject.material.color != null
val options = (js("{}") as JSONEditorOptions).apply {
mode = "form"
onChangeJSON = { item.config.update(DynamicMeta(it.asDynamic())) }
}
JSONEditor(this, options, jsObject)
}
}
}