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