From 43362f51f5642941c16550043da99f9f0b525458 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 13 Aug 2022 20:47:03 +0300 Subject: [PATCH] Fix styling for Prototypes --- .../ThreeViewWithControls.kt | 11 +++-- .../space/kscience/visionforge/StyleSheet.kt | 6 +-- .../kscience/visionforge/VisionProperties.kt | 10 +++-- .../visionforge/solid/SolidReference.kt | 43 ++++++++++++++----- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeViewWithControls.kt b/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeViewWithControls.kt index babafb2e..883b621d 100644 --- a/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeViewWithControls.kt +++ b/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeViewWithControls.kt @@ -5,7 +5,9 @@ import kotlinx.coroutines.async import kotlinx.coroutines.launch import kotlinx.css.* import react.* +import react.dom.b import react.dom.div +import react.dom.p import react.dom.span import ringui.* import space.kscience.dataforge.context.Context @@ -14,14 +16,11 @@ import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.NameToken import space.kscience.dataforge.names.isEmpty import space.kscience.dataforge.names.length -import space.kscience.visionforge.Vision +import space.kscience.visionforge.* import space.kscience.visionforge.react.* -import space.kscience.visionforge.root -import space.kscience.visionforge.setAsRoot import space.kscience.visionforge.solid.Solid import space.kscience.visionforge.solid.SolidGroup import space.kscience.visionforge.solid.specifications.Canvas3DOptions -import space.kscience.visionforge.visionManager import styled.css import styled.styledDiv @@ -184,6 +183,10 @@ public val ThreeCanvasWithControls: FC = fc("Three } } } + p { + b { +"Styles: " } + +vision.styles.joinToString(separator = ", ") + } } } } diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleSheet.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleSheet.kt index 11e76d0c..9db79e19 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleSheet.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleSheet.kt @@ -67,11 +67,7 @@ internal fun Vision.styleChanged(key: String, oldStyle: Meta?, newStyle: Meta?) * List of names of styles applied to this object. Order matters. Not inherited. */ public var Vision.styles: List - get() = properties.getValue( - Vision.STYLE_KEY, - inherit = true, - includeStyles = false, - )?.stringList ?: emptyList() + get() = properties.getValue(Vision.STYLE_KEY, inherit = false, includeStyles = false)?.stringList ?: emptyList() set(value) { properties.setValue(Vision.STYLE_KEY, value.map { it.asValue() }.asValue()) } diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt index c15c6c55..fd7befdf 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt @@ -167,16 +167,18 @@ public abstract class AbstractVisionProperties( inherit: Boolean?, includeStyles: Boolean?, ): Value? { + own?.get(name)?.value?.let { return it } + val descriptor = descriptor?.get(name) - val inheritFlag = inherit ?: descriptor?.inherited ?: false val stylesFlag = includeStyles ?: descriptor?.usesStyles ?: true - own?.get(name)?.value?.let { return it } if (stylesFlag) { vision.getStyleProperty(name)?.value?.let { return it } } + + val inheritFlag = inherit ?: descriptor?.inherited ?: false if (inheritFlag) { - vision.parent?.properties?.getValue(name, inherit, includeStyles)?.let { return it } + vision.parent?.properties?.getValue(name, inheritFlag, stylesFlag)?.let { return it } } return descriptor?.defaultValue } @@ -208,7 +210,7 @@ public abstract class AbstractVisionProperties( } @Transient - protected val changesInternal = MutableSharedFlow() + protected val changesInternal: MutableSharedFlow = MutableSharedFlow() override val changes: SharedFlow get() = changesInternal override fun invalidate(propertyName: Name) { diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidReference.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidReference.kt index 1c123632..2cf90987 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidReference.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidReference.kt @@ -9,6 +9,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import space.kscience.dataforge.meta.* import space.kscience.dataforge.meta.descriptors.MetaDescriptor +import space.kscience.dataforge.meta.descriptors.get import space.kscience.dataforge.names.* import space.kscience.visionforge.* import space.kscience.visionforge.AbstractVisionGroup.Companion.updateProperties @@ -59,16 +60,41 @@ public class SolidReference( propertiesInternal = value } - override val own: Meta? get() = properties - - override fun getProperty(name: Name, inherit: Boolean?, includeStyles: Boolean?): MutableMeta { - return properties?.getMeta(name) ?: prototype.properties.getProperty(name, inherit, includeStyles) - } - override fun getValue(name: Name, inherit: Boolean?, includeStyles: Boolean?): Value? { - return properties?.getValue(name) ?: prototype.properties.getValue(name, inherit, includeStyles) + if(name == Vision.STYLE_KEY){ + return buildList { + properties?.getValue(Vision.STYLE_KEY)?.list?.forEach { + add(it) + } + prototype.styles.forEach { + add(it.asValue()) + } + }.distinct().asValue() + } + properties?.getValue(name)?.let { return it } + + val descriptor = descriptor?.get(name) + val inheritFlag = inherit ?: descriptor?.inherited ?: false + val stylesFlag = includeStyles ?: descriptor?.usesStyles ?: true + + if (stylesFlag) { + getStyleProperty(name)?.value?.let { return it } + } + + if (inheritFlag) { + parent?.properties?.getValue(name, inherit, includeStyles)?.let { return it } + } + + prototype.properties.getValue(name, inheritFlag, stylesFlag)?.let { return it } + + if(inheritFlag){ + parent?.properties?.getValue(name, inheritFlag, includeStyles)?.let { return it } + } + + return null } + override fun invalidate(propertyName: Name) { //send update signal @OptIn(DelicateCoroutinesApi::class) @@ -130,9 +156,6 @@ internal class SolidReferenceChild( override val own: MutableMeta by lazy { owner.properties.getProperty(childToken(childName).asName()) } - override fun getProperty(name: Name, inherit: Boolean?, includeStyles: Boolean?): MutableMeta = - own.getMeta(name) ?: prototype.properties.getProperty(name, inherit, includeStyles) - override fun getValue( name: Name, inherit: Boolean?,