Fix SO in style definition

This commit is contained in:
Alexander Nozik 2020-08-08 09:57:02 +03:00
parent 423b36b3de
commit c60c8564e1
9 changed files with 24 additions and 30 deletions

View File

@ -51,7 +51,7 @@ val MMApp = component<MMAppProps> { props ->
div("row") {
h1("mx-auto") {
+"GDML/JSON render demo"
+"Muon monitor demo"
}
}
div("row") {

View File

@ -27,5 +27,5 @@ kotlin {
}
application {
mainClassName = "hep.dataforge.vis.solid.demo.FXDemoAppKt"
mainClassName = "hep.dataforge.vision.solid.demo.FXDemoAppKt"
}

View File

@ -21,7 +21,8 @@ abstract class AbstractVision : Vision {
/**
* Object own properties excluding styles and inheritance
*/
protected abstract var properties: Config?
abstract override var properties: Config?
protected set
protected fun updateStyles(names: List<String>) {
styleCache = null
@ -64,6 +65,10 @@ abstract class AbstractVision : Vision {
listeners.removeAll { it.owner == owner }
}
protected fun getStyleItem(name: Name): MetaItem<*>?{
return styles.asSequence().map { resolveStyle(it) }.map { it[name] }.firstOrNull()
}
private var styleCache: Meta? = null
/**
@ -83,13 +88,13 @@ abstract class AbstractVision : Vision {
return if (inherit) {
sequence {
yield(properties?.get(name))
yield(mergedStyles[name])
yield(getStyleItem(name))
yield(parent?.getProperty(name, inherit))
}.merge()
} else {
sequence {
yield(properties?.get(name))
yield(mergedStyles[name])
yield(getStyleItem(name))
}.merge()
}
}

View File

@ -94,7 +94,7 @@ class StyleSheet private constructor(private val styleMap: MutableMap<String, Me
* List of names of styles applied to this object. Order matters. Not inherited
*/
var Vision.styles: List<String>
get() = getItem(Vision.STYLE_KEY).stringList
get() = properties?.get(Vision.STYLE_KEY).stringList
set(value) {
setItem(Vision.STYLE_KEY,value.map { it.asValue() }.asValue())
}

View File

@ -1,9 +1,6 @@
package hep.dataforge.vision
import hep.dataforge.meta.Configurable
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaItem
import hep.dataforge.meta.*
import hep.dataforge.names.Name
import hep.dataforge.names.asName
import hep.dataforge.names.toName
@ -24,6 +21,11 @@ interface Vision : Configurable {
@Transient
var parent: VisionGroup?
/**
* Nullable version of [config] used to check if this [Vision] has custom properties
*/
val properties: Config?
/**
* All properties including styles and prototypes if present, including inherited ones
*/

View File

@ -9,7 +9,7 @@ import hep.dataforge.values.ValueType
import hep.dataforge.values.asValue
fun Sequence<MetaItem<*>?>.merge(): MetaItem<*>? {
return when (val first = filterNotNull().firstOrNull()) {
return when (val first = firstOrNull { it != null }) {
null -> null
is MetaItem.ValueItem -> first //fast search for first entry if it is value
is MetaItem.NodeItem -> {

View File

@ -48,14 +48,14 @@ class Proxy private constructor(
return if (inherit) {
sequence {
yield(properties?.get(name))
yield(mergedStyles[name])
yield(getStyleItem(name))
yield(prototype.getItem(name))
yield(parent?.getProperty(name, inherit))
}.merge()
} else {
sequence {
yield(properties?.get(name))
yield(mergedStyles[name])
yield(getStyleItem(name))
yield(prototype.getProperty(name, false))
}.merge()
}
@ -92,8 +92,7 @@ class Proxy private constructor(
override val descriptor: NodeDescriptor?
get() = prototype.descriptor
inner class ProxyChild(val name: Name) : AbstractVision(),
VisionGroup {
inner class ProxyChild(val name: Name) : AbstractVision(), VisionGroup {
val prototype: Vision get() = prototypeFor(name)
@ -127,14 +126,14 @@ class Proxy private constructor(
return if (inherit) {
sequence {
yield(properties?.get(name))
yield(mergedStyles[name])
yield(getStyleItem(name))
yield(prototype.getItem(name))
yield(parent?.getProperty(name, inherit))
}.merge()
} else {
sequence {
yield(properties?.get(name))
yield(mergedStyles[name])
yield(getStyleItem(name))
yield(prototype.getProperty(name, false))
}.merge()
}

View File

@ -25,8 +25,6 @@ interface Solid : Vision {
var rotation: Point3D?
var scale: Point3D?
val properties: Config?
override val descriptor: NodeDescriptor? get() = Companion.descriptor
companion object {

View File

@ -51,16 +51,6 @@ private class SolidForm<T :Solid>(
private fun SerialModule.extractFactories(): List<SolidForm<*>> {
val list = ArrayList<SolidForm<*>>()
val jsonEngine = Json(
JsonConfiguration(
prettyPrint = true,
useArrayPolymorphism = false,
encodeDefaults = false,
ignoreUnknownKeys = true
),
context = this
)
val collector = object : SerialModuleCollector {
override fun <T : Any> contextual(kClass: KClass<T>, serializer: KSerializer<T>) {
//Do nothing