Fix styling for Prototypes
This commit is contained in:
parent
c586a2ea14
commit
43362f51f5
@ -5,7 +5,9 @@ import kotlinx.coroutines.async
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.css.*
|
import kotlinx.css.*
|
||||||
import react.*
|
import react.*
|
||||||
|
import react.dom.b
|
||||||
import react.dom.div
|
import react.dom.div
|
||||||
|
import react.dom.p
|
||||||
import react.dom.span
|
import react.dom.span
|
||||||
import ringui.*
|
import ringui.*
|
||||||
import space.kscience.dataforge.context.Context
|
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.NameToken
|
||||||
import space.kscience.dataforge.names.isEmpty
|
import space.kscience.dataforge.names.isEmpty
|
||||||
import space.kscience.dataforge.names.length
|
import space.kscience.dataforge.names.length
|
||||||
import space.kscience.visionforge.Vision
|
import space.kscience.visionforge.*
|
||||||
import space.kscience.visionforge.react.*
|
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.Solid
|
||||||
import space.kscience.visionforge.solid.SolidGroup
|
import space.kscience.visionforge.solid.SolidGroup
|
||||||
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
|
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
|
||||||
import space.kscience.visionforge.visionManager
|
|
||||||
import styled.css
|
import styled.css
|
||||||
import styled.styledDiv
|
import styled.styledDiv
|
||||||
|
|
||||||
@ -184,6 +183,10 @@ public val ThreeCanvasWithControls: FC<ThreeCanvasWithControlsProps> = fc("Three
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
p {
|
||||||
|
b { +"Styles: " }
|
||||||
|
+vision.styles.joinToString(separator = ", ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* List of names of styles applied to this object. Order matters. Not inherited.
|
||||||
*/
|
*/
|
||||||
public var Vision.styles: List<String>
|
public var Vision.styles: List<String>
|
||||||
get() = properties.getValue(
|
get() = properties.getValue(Vision.STYLE_KEY, inherit = false, includeStyles = false)?.stringList ?: emptyList()
|
||||||
Vision.STYLE_KEY,
|
|
||||||
inherit = true,
|
|
||||||
includeStyles = false,
|
|
||||||
)?.stringList ?: emptyList()
|
|
||||||
set(value) {
|
set(value) {
|
||||||
properties.setValue(Vision.STYLE_KEY, value.map { it.asValue() }.asValue())
|
properties.setValue(Vision.STYLE_KEY, value.map { it.asValue() }.asValue())
|
||||||
}
|
}
|
||||||
|
@ -167,16 +167,18 @@ public abstract class AbstractVisionProperties(
|
|||||||
inherit: Boolean?,
|
inherit: Boolean?,
|
||||||
includeStyles: Boolean?,
|
includeStyles: Boolean?,
|
||||||
): Value? {
|
): Value? {
|
||||||
|
own?.get(name)?.value?.let { return it }
|
||||||
|
|
||||||
val descriptor = descriptor?.get(name)
|
val descriptor = descriptor?.get(name)
|
||||||
val inheritFlag = inherit ?: descriptor?.inherited ?: false
|
|
||||||
val stylesFlag = includeStyles ?: descriptor?.usesStyles ?: true
|
val stylesFlag = includeStyles ?: descriptor?.usesStyles ?: true
|
||||||
|
|
||||||
own?.get(name)?.value?.let { return it }
|
|
||||||
if (stylesFlag) {
|
if (stylesFlag) {
|
||||||
vision.getStyleProperty(name)?.value?.let { return it }
|
vision.getStyleProperty(name)?.value?.let { return it }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val inheritFlag = inherit ?: descriptor?.inherited ?: false
|
||||||
if (inheritFlag) {
|
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
|
return descriptor?.defaultValue
|
||||||
}
|
}
|
||||||
@ -208,7 +210,7 @@ public abstract class AbstractVisionProperties(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
protected val changesInternal = MutableSharedFlow<Name>()
|
protected val changesInternal: MutableSharedFlow<Name> = MutableSharedFlow<Name>()
|
||||||
override val changes: SharedFlow<Name> get() = changesInternal
|
override val changes: SharedFlow<Name> get() = changesInternal
|
||||||
|
|
||||||
override fun invalidate(propertyName: Name) {
|
override fun invalidate(propertyName: Name) {
|
||||||
|
@ -9,6 +9,7 @@ import kotlinx.serialization.Serializable
|
|||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
import space.kscience.dataforge.meta.*
|
import space.kscience.dataforge.meta.*
|
||||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||||
|
import space.kscience.dataforge.meta.descriptors.get
|
||||||
import space.kscience.dataforge.names.*
|
import space.kscience.dataforge.names.*
|
||||||
import space.kscience.visionforge.*
|
import space.kscience.visionforge.*
|
||||||
import space.kscience.visionforge.AbstractVisionGroup.Companion.updateProperties
|
import space.kscience.visionforge.AbstractVisionGroup.Companion.updateProperties
|
||||||
@ -59,15 +60,40 @@ public class SolidReference(
|
|||||||
propertiesInternal = value
|
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? {
|
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) {
|
override fun invalidate(propertyName: Name) {
|
||||||
//send update signal
|
//send update signal
|
||||||
@ -130,9 +156,6 @@ internal class SolidReferenceChild(
|
|||||||
|
|
||||||
override val own: MutableMeta by lazy { owner.properties.getProperty(childToken(childName).asName()) }
|
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(
|
override fun getValue(
|
||||||
name: Name,
|
name: Name,
|
||||||
inherit: Boolean?,
|
inherit: Boolean?,
|
||||||
|
Loading…
Reference in New Issue
Block a user