Compare commits
3 Commits
da0f4c0ff0
...
067ed4aa3d
Author | SHA1 | Date | |
---|---|---|---|
067ed4aa3d | |||
30f6d51745 | |||
15ac3545b5 |
@ -25,4 +25,6 @@ public interface ComposeVisionRenderer: ElementVisionRenderer {
|
||||
render(client, name, vision, meta)
|
||||
}
|
||||
}
|
||||
|
||||
public companion object
|
||||
}
|
@ -31,7 +31,6 @@ public sealed class EditorPropertyState {
|
||||
public data object Defined : EditorPropertyState()
|
||||
public data class Default(public val source: String = "unknown") : EditorPropertyState()
|
||||
public data object Undefined : EditorPropertyState()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,13 +43,13 @@ public fun PropertyEditor(
|
||||
rootMeta: MutableMeta,
|
||||
getPropertyState: (Name) -> EditorPropertyState,
|
||||
updates: Flow<Name>,
|
||||
name: Name = Name.EMPTY,
|
||||
rootDescriptor: MetaDescriptor? = null,
|
||||
name: Name,
|
||||
rootDescriptor: MetaDescriptor?,
|
||||
initialExpanded: Boolean? = null,
|
||||
) {
|
||||
var expanded: Boolean by remember { mutableStateOf(initialExpanded ?: true) }
|
||||
val descriptor: MetaDescriptor? = remember(rootDescriptor, name) { rootDescriptor?.get(name) }
|
||||
var property: MutableMeta by remember { mutableStateOf(rootMeta.getOrCreate(name)) }
|
||||
val descriptor: MetaDescriptor? by derivedStateOf { rootDescriptor?.get(name) }
|
||||
var displayedValue by remember { mutableStateOf(rootMeta.getValue(name)) }
|
||||
var editorPropertyState: EditorPropertyState by remember { mutableStateOf(getPropertyState(name)) }
|
||||
|
||||
|
||||
@ -68,13 +67,13 @@ public fun PropertyEditor(
|
||||
val token = name.lastOrNull()?.toString() ?: "Properties"
|
||||
|
||||
fun update() {
|
||||
property = rootMeta.getOrCreate(name)
|
||||
displayedValue = rootMeta.getValue(name)
|
||||
editorPropertyState = getPropertyState(name)
|
||||
}
|
||||
|
||||
LaunchedEffect(rootMeta) {
|
||||
updates.collect { updatedName ->
|
||||
if (updatedName == name) {
|
||||
if (name.startsWith(updatedName)) {
|
||||
update()
|
||||
}
|
||||
}
|
||||
@ -85,6 +84,7 @@ public fun PropertyEditor(
|
||||
alignItems(AlignItems.Center)
|
||||
}
|
||||
}) {
|
||||
//if node has children
|
||||
if (keys.isNotEmpty()) {
|
||||
Span({
|
||||
classes(TreeStyles.treeCaret)
|
||||
@ -96,8 +96,12 @@ public fun PropertyEditor(
|
||||
}
|
||||
Span({
|
||||
classes(TreeStyles.treeLabel)
|
||||
if (editorPropertyState != EditorPropertyState.Defined) {
|
||||
classes(TreeStyles.treeLabelInactive)
|
||||
when (editorPropertyState) {
|
||||
is EditorPropertyState.Default, EditorPropertyState.Undefined -> {
|
||||
classes(TreeStyles.treeLabelInactive)
|
||||
}
|
||||
|
||||
EditorPropertyState.Defined -> {}
|
||||
}
|
||||
}) {
|
||||
Text(token)
|
||||
@ -110,13 +114,15 @@ public fun PropertyEditor(
|
||||
marginAll(1.px, 5.px)
|
||||
}
|
||||
}) {
|
||||
ValueChooser(descriptor, editorPropertyState, property.value) {
|
||||
property.value = it
|
||||
editorPropertyState = getPropertyState(name)
|
||||
ValueChooser(descriptor, editorPropertyState, displayedValue) {
|
||||
rootMeta.setValue(name, it)
|
||||
update()
|
||||
}
|
||||
}
|
||||
|
||||
CloseButton(editorPropertyState != EditorPropertyState.Defined){
|
||||
}
|
||||
if (!name.isEmpty()) {
|
||||
CloseButton(editorPropertyState != EditorPropertyState.Defined) {
|
||||
rootMeta.remove(name)
|
||||
update()
|
||||
}
|
||||
@ -163,7 +169,7 @@ public fun PropertyEditor(
|
||||
}
|
||||
}
|
||||
|
||||
awaitClose { properties.removeListener(scope) }
|
||||
awaitClose { properties.removeListener(scope) }
|
||||
},
|
||||
name = Name.EMPTY,
|
||||
rootDescriptor = descriptor,
|
||||
|
@ -1,11 +1,9 @@
|
||||
package space.kscience.visionforge
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
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
|
||||
@ -233,15 +231,12 @@ public abstract class AbstractVisionProperties(
|
||||
}
|
||||
|
||||
@Transient
|
||||
protected val changesInternal: MutableSharedFlow<Name> = MutableSharedFlow<Name>()
|
||||
protected val changesInternal: MutableSharedFlow<Name> = MutableSharedFlow(500, onBufferOverflow = BufferOverflow.DROP_OLDEST)
|
||||
override val changes: SharedFlow<Name> get() = changesInternal
|
||||
|
||||
override fun invalidate(propertyName: Name) {
|
||||
//send update signal
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
(vision.manager?.context ?: GlobalScope).launch {
|
||||
changesInternal.emit(propertyName)
|
||||
}
|
||||
changesInternal.tryEmit(propertyName)
|
||||
|
||||
//notify children if there are any
|
||||
if (vision is VisionGroup) {
|
||||
@ -280,8 +275,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,
|
||||
@ -297,22 +292,3 @@ 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)
|
@ -155,9 +155,10 @@ public class ThreeCanvas(
|
||||
}
|
||||
|
||||
//Clipping planes
|
||||
options.useProperty(Canvas3DOptions::clipping) { clipping ->
|
||||
if (!clipping.meta.isEmpty()) {
|
||||
renderer.localClippingEnabled = true
|
||||
options.useProperty(Canvas3DOptions::clipping) { clipping: PointScheme ->
|
||||
if (clipping.meta.isEmpty()) {
|
||||
renderer.clippingPlanes = emptyArray()
|
||||
} else {
|
||||
boundingBox?.let { boundingBox ->
|
||||
val xClippingPlane = clipping.x?.let {
|
||||
val absoluteValue = boundingBox.min.x + (boundingBox.max.x - boundingBox.min.x) * it
|
||||
@ -175,8 +176,6 @@ public class ThreeCanvas(
|
||||
renderer.clippingPlanes =
|
||||
listOfNotNull(xClippingPlane, yClippingPlane, zClippingPlane).toTypedArray()
|
||||
}
|
||||
} else {
|
||||
renderer.localClippingEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,6 +148,7 @@ public fun ThreeView(
|
||||
EditorPropertyState.Undefined
|
||||
}
|
||||
},
|
||||
name = Name.EMPTY,
|
||||
updates = vision.properties.changes,
|
||||
rootDescriptor = vision.descriptor
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user