Hide nodes without visible children in the property editor

This commit is contained in:
Alexander Nozik 2021-01-13 10:58:50 +03:00
parent f7301805fd
commit 4820082248
3 changed files with 14 additions and 13 deletions

View File

@ -45,7 +45,7 @@ public val TabPane: FunctionalComponent<TabPaneProps> = functionalComponent("Tab
+(cp.title ?: cp.id) +(cp.title ?: cp.id)
attrs { attrs {
if (cp.id == activeTab) { if (cp.id == activeTab) {
classes += "active" classes = classes + "active"
} }
onClickFunction = { onClickFunction = {
activeTab = cp.id activeTab = cp.id

View File

@ -22,7 +22,7 @@ public external interface ThreeControlsProps : RProps {
@JsExport @JsExport
public val ThreeControls: FunctionalComponent<ThreeControlsProps> = functionalComponent { props -> public val ThreeControls: FunctionalComponent<ThreeControlsProps> = functionalComponent { props ->
val vision = props.canvas.content val vision = props.canvas.content
tabPane { tabPane(if (props.selected != null) "Properties" else null) {
tab("Canvas") { tab("Canvas") {
card("Canvas configuration") { card("Canvas configuration") {
canvasControls(props.canvas) canvasControls(props.canvas)

View File

@ -66,12 +66,9 @@ private val PropertyEditorItem: FunctionalComponent<PropertyEditorProps> =
private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
var expanded: Boolean by useState { true } var expanded: Boolean by useState { true }
val descriptorItem: ItemDescriptor? = props.descriptor?.get(props.name) val descriptorItem: ItemDescriptor? = props.descriptor?.get(props.name)
if (descriptorItem?.hidden == true) return //fail fast for hidden property
var ownProperty: MetaItem? by useState { props.ownProperties.getItem(props.name) } var ownProperty: MetaItem? by useState { props.ownProperties.getItem(props.name) }
val actualItem: MetaItem? = props.allProperties?.getItem(props.name) val actualItem: MetaItem? = props.allProperties?.getItem(props.name)
println("Actual item for ${props.name?.toString()} is ${actualItem.toString()}")
val token = props.name.lastOrNull()?.toString() ?: "Properties" val token = props.name.lastOrNull()?.toString() ?: "Properties"
fun update() { fun update() {
@ -108,6 +105,17 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
} }
if (actualItem is NodeItem) { if (actualItem is NodeItem) {
val keys = buildSet {
(descriptorItem as? NodeDescriptor)?.items?.filterNot {
it.key.startsWith("@") || it.value.hidden
}?.forEach {
add(NameToken(it.key))
}
ownProperty?.node?.items?.keys?.filterNot { it.body.startsWith("@") }?.let { addAll(it) }
}
// Do not show nodes without visible children
if (keys.isEmpty()) return
styledDiv { styledDiv {
css { css {
+TreeStyles.treeLeaf +TreeStyles.treeLeaf
@ -138,14 +146,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
css { css {
+TreeStyles.tree +TreeStyles.tree
} }
val keys = buildSet { keys.forEach { token ->
(descriptorItem as? NodeDescriptor)?.items?.keys?.forEach {
add(NameToken(it))
}
ownProperty?.node?.items?.keys?.let { addAll(it) }
}
keys.filter { !it.body.startsWith("@") }.forEach { token ->
styledLi { styledLi {
css { css {
+TreeStyles.treeItem +TreeStyles.treeItem