Property editor minor refactoring

This commit is contained in:
Alexander Nozik 2024-01-01 14:07:08 +03:00
parent 15ac3545b5
commit 30f6d51745
3 changed files with 17 additions and 36 deletions

View File

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

View File

@ -49,8 +49,8 @@ public fun PropertyEditor(
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 +68,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 +85,7 @@ public fun PropertyEditor(
alignItems(AlignItems.Center)
}
}) {
//if node has children
if (keys.isNotEmpty()) {
Span({
classes(TreeStyles.treeCaret)
@ -110,12 +111,14 @@ 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()
}
}
}
if (!name.isEmpty()) {
CloseButton(editorPropertyState != EditorPropertyState.Defined) {
rootMeta.remove(name)
update()

View File

@ -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)