Compare commits

..

No commits in common. "067ed4aa3d5a4d8287d5a779b414bfe048289cdf" and "da0f4c0ff04a516221d518aeb44842043ea31902" have entirely different histories.

5 changed files with 48 additions and 32 deletions

View File

@ -25,6 +25,4 @@ public interface ComposeVisionRenderer: ElementVisionRenderer {
render(client, name, vision, meta)
}
}
public companion object
}

View File

@ -31,6 +31,7 @@ public sealed class EditorPropertyState {
public data object Defined : EditorPropertyState()
public data class Default(public val source: String = "unknown") : EditorPropertyState()
public data object Undefined : EditorPropertyState()
}
/**
@ -43,13 +44,13 @@ public fun PropertyEditor(
rootMeta: MutableMeta,
getPropertyState: (Name) -> EditorPropertyState,
updates: Flow<Name>,
name: Name,
rootDescriptor: MetaDescriptor?,
name: Name = Name.EMPTY,
rootDescriptor: MetaDescriptor? = null,
initialExpanded: Boolean? = null,
) {
var expanded: Boolean by remember { mutableStateOf(initialExpanded ?: true) }
val descriptor: MetaDescriptor? by derivedStateOf { rootDescriptor?.get(name) }
var displayedValue by remember { mutableStateOf(rootMeta.getValue(name)) }
val descriptor: MetaDescriptor? = remember(rootDescriptor, name) { rootDescriptor?.get(name) }
var property: MutableMeta by remember { mutableStateOf(rootMeta.getOrCreate(name)) }
var editorPropertyState: EditorPropertyState by remember { mutableStateOf(getPropertyState(name)) }
@ -67,13 +68,13 @@ public fun PropertyEditor(
val token = name.lastOrNull()?.toString() ?: "Properties"
fun update() {
displayedValue = rootMeta.getValue(name)
property = rootMeta.getOrCreate(name)
editorPropertyState = getPropertyState(name)
}
LaunchedEffect(rootMeta) {
updates.collect { updatedName ->
if (name.startsWith(updatedName)) {
if (updatedName == name) {
update()
}
}
@ -84,7 +85,6 @@ public fun PropertyEditor(
alignItems(AlignItems.Center)
}
}) {
//if node has children
if (keys.isNotEmpty()) {
Span({
classes(TreeStyles.treeCaret)
@ -96,12 +96,8 @@ public fun PropertyEditor(
}
Span({
classes(TreeStyles.treeLabel)
when (editorPropertyState) {
is EditorPropertyState.Default, EditorPropertyState.Undefined -> {
classes(TreeStyles.treeLabelInactive)
}
EditorPropertyState.Defined -> {}
if (editorPropertyState != EditorPropertyState.Defined) {
classes(TreeStyles.treeLabelInactive)
}
}) {
Text(token)
@ -114,15 +110,13 @@ public fun PropertyEditor(
marginAll(1.px, 5.px)
}
}) {
ValueChooser(descriptor, editorPropertyState, displayedValue) {
rootMeta.setValue(name, it)
update()
ValueChooser(descriptor, editorPropertyState, property.value) {
property.value = it
editorPropertyState = getPropertyState(name)
}
}
}
if (!name.isEmpty()) {
CloseButton(editorPropertyState != EditorPropertyState.Defined) {
CloseButton(editorPropertyState != EditorPropertyState.Defined){
rootMeta.remove(name)
update()
}
@ -169,7 +163,7 @@ public fun PropertyEditor(
}
}
awaitClose { properties.removeListener(scope) }
awaitClose { properties.removeListener(scope) }
},
name = Name.EMPTY,
rootDescriptor = descriptor,

View File

@ -1,9 +1,11 @@
package space.kscience.visionforge
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch
import kotlinx.serialization.Transient
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
@ -231,12 +233,15 @@ public abstract class AbstractVisionProperties(
}
@Transient
protected val changesInternal: MutableSharedFlow<Name> = MutableSharedFlow(500, onBufferOverflow = BufferOverflow.DROP_OLDEST)
protected val changesInternal: MutableSharedFlow<Name> = MutableSharedFlow<Name>()
override val changes: SharedFlow<Name> get() = changesInternal
override fun invalidate(propertyName: Name) {
//send update signal
changesInternal.tryEmit(propertyName)
@OptIn(DelicateCoroutinesApi::class)
(vision.manager?.context ?: GlobalScope).launch {
changesInternal.emit(propertyName)
}
//notify children if there are any
if (vision is VisionGroup) {
@ -275,8 +280,8 @@ public operator fun VisionProperties.get(
/**
* The root property node with given inheritance and style flags
* @param inherit inherit properties from the [Vision] parent. If null, infer from descriptor
* @param includeStyles include style information. If null, infer from descriptor
* @param inherit - inherit properties from the [Vision] parent. If null, infer from descriptor
* @param includeStyles - include style information. If null, infer from descriptor
*/
public fun MutableVisionProperties.root(
inherit: Boolean? = null,
@ -292,3 +297,22 @@ public operator fun MutableVisionProperties.get(
inherit: Boolean? = null,
includeStyles: Boolean? = null,
): MutableMeta = get(name.parseAsName(), inherit, includeStyles)
//
//public operator fun MutableVisionProperties.set(name: Name, value: Number): Unit =
// setValue(name, value.asValue())
//
//public operator fun MutableVisionProperties.set(name: String, value: Number): Unit =
// set(name.parseAsName(), value)
//
//public operator fun MutableVisionProperties.set(name: Name, value: Boolean): Unit =
// setValue(name, value.asValue())
//
//public operator fun MutableVisionProperties.set(name: String, value: Boolean): Unit =
// set(name.parseAsName(), value)
//
//public operator fun MutableVisionProperties.set(name: Name, value: String): Unit =
// setValue(name, value.asValue())
//
//public operator fun MutableVisionProperties.set(name: String, value: String): Unit =
// set(name.parseAsName(), value)

View File

@ -155,10 +155,9 @@ public class ThreeCanvas(
}
//Clipping planes
options.useProperty(Canvas3DOptions::clipping) { clipping: PointScheme ->
if (clipping.meta.isEmpty()) {
renderer.clippingPlanes = emptyArray()
} else {
options.useProperty(Canvas3DOptions::clipping) { clipping ->
if (!clipping.meta.isEmpty()) {
renderer.localClippingEnabled = true
boundingBox?.let { boundingBox ->
val xClippingPlane = clipping.x?.let {
val absoluteValue = boundingBox.min.x + (boundingBox.max.x - boundingBox.min.x) * it
@ -176,6 +175,8 @@ public class ThreeCanvas(
renderer.clippingPlanes =
listOfNotNull(xClippingPlane, yClippingPlane, zClippingPlane).toTypedArray()
}
} else {
renderer.localClippingEnabled = false
}
}

View File

@ -148,7 +148,6 @@ public fun ThreeView(
EditorPropertyState.Undefined
}
},
name = Name.EMPTY,
updates = vision.properties.changes,
rootDescriptor = vision.descriptor
)