diff --git a/editor/src/messages/layout/utility_types/layout_widget.rs b/editor/src/messages/layout/utility_types/layout_widget.rs index 0dc7a14c07..c964448106 100644 --- a/editor/src/messages/layout/utility_types/layout_widget.rs +++ b/editor/src/messages/layout/utility_types/layout_widget.rs @@ -423,9 +423,15 @@ pub struct NodeSection { /// For a section in the chain feeding another section's input, the wire drawn up to the section above, which its node's output feeds. #[serde(rename = "outputWire")] pub output_wire: Option, - /// Whether this section only refers to its node with a row like the Data panel's, in place of its header and parameters (for the layer whose stack feeds the bottom of a chain). + /// Whether this section only refers to its node with a row like the Data panel's, in place of its header and parameters (for a layer feeding a chain, or feeding or fed by the selected layer). #[serde(rename = "nodeReference")] pub node_reference: bool, + /// For a section referring to layers that take the wire from the section below into their content, rather than from their bottom, that wire turning in from the left past its indent. + #[serde(rename = "contentWire")] + pub content_wire: Option, + /// Whether the content wire also continues up past its turn, to the section above that takes it from the bottom. + #[serde(rename = "contentWireContinues")] + pub content_wire_continues: bool, /// Whether this section is expanded to show its contents, as opposed to being collapsed down to just its header. pub expanded: bool, /// The ID of the node whose Inspector section this is. @@ -477,6 +483,8 @@ impl LayoutGroup { chain_wire: None, output_wire: None, node_reference: false, + content_wire: None, + content_wire_continues: false, expanded, id, layout, @@ -582,6 +590,8 @@ impl Diffable for LayoutGroup { chain_wire: current_chain_wire, output_wire: current_output_wire, node_reference: current_node_reference, + content_wire: current_content_wire, + content_wire_continues: current_content_wire_continues, expanded: current_expanded, id: current_id, layout: current_layout, @@ -596,6 +606,8 @@ impl Diffable for LayoutGroup { chain_wire: new_chain_wire, output_wire: new_output_wire, node_reference: new_node_reference, + content_wire: new_content_wire, + content_wire_continues: new_content_wire_continues, expanded: new_expanded, id: new_id, layout: new_layout, @@ -613,6 +625,8 @@ impl Diffable for LayoutGroup { || *current_chain_wire != new_chain_wire || *current_output_wire != new_output_wire || *current_node_reference != new_node_reference + || *current_content_wire != new_content_wire + || *current_content_wire_continues != new_content_wire_continues || *current_expanded != new_expanded || *current_id != new_id { @@ -626,6 +640,8 @@ impl Diffable for LayoutGroup { *current_chain_wire = new_chain_wire; *current_output_wire = new_output_wire; *current_node_reference = new_node_reference; + *current_content_wire = new_content_wire; + *current_content_wire_continues = new_content_wire_continues; *current_expanded = new_expanded; *current_id = new_id; current_layout.clone_from(&new_layout); @@ -641,6 +657,8 @@ impl Diffable for LayoutGroup { chain_wire: new_chain_wire, output_wire: new_output_wire, node_reference: new_node_reference, + content_wire: new_content_wire, + content_wire_continues: new_content_wire_continues, expanded: new_expanded, id: new_id, layout: new_layout, diff --git a/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs b/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs index 0eb405616e..cdd0469356 100644 --- a/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs +++ b/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs @@ -1044,7 +1044,7 @@ pub fn node_reference_button( network_path: &[NodeId], selection_network_path: &[NodeId], select: impl Fn() -> Message + Send + Sync + 'static, -) -> WidgetInstance { +) -> TextButton { let is_layer = network_interface.is_layer(&node_id, network_path); let icon = network_interface.node_icon(&node_id, network_path); let name = network_interface.display_name(&node_id, network_path); @@ -1063,7 +1063,6 @@ pub fn node_reference_button( (true, false, _) => "", }) .on_update(move |_| select()) - .widget_instance() } impl TableItemLayout for NodeId { @@ -1097,7 +1096,7 @@ impl TableItemLayout for NodeId { NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into(), ]), }; - vec![node_reference_button(node_id, network_interface, &network_path, data.selection_network_path, select)] + vec![node_reference_button(node_id, network_interface, &network_path, data.selection_network_path, select).widget_instance()] } fn value_page(&self, data: &mut LayoutData) -> Vec { vec![LayoutGroup::row(self.value_widgets(PathStep::Element(0), data))] diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs index c4228ccc68..8c045b4dff 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs @@ -3076,7 +3076,73 @@ impl NodeGraphMessageHandler { } } - vec![layer_section] + // The layers this one's output feeds, which a stack used in several places can be many of, and the graph's output none of. + // Followed through any nodes between, each layer takes it either from its bottom (as the sibling above in its stack) or into its content (as its parent). + let network_path = context.selection_network_path; + let outward_connectors = |node_id: NodeId| { + context + .network_interface + .with_outward_wires(network_path, |outward_wires| outward_wires.get(&OutputConnector::primary_output(node_id)).cloned()) + .flatten() + .unwrap_or_default() + }; + let (mut siblings, mut parents) = (Vec::new(), Vec::new()); + let mut pending_connectors = outward_connectors(layer); + let mut visited_nodes = HashSet::new(); + while let Some(connector) = pending_connectors.pop() { + let Some(node_id) = connector.node_id() else { continue }; + + if context.network_interface.is_layer(&node_id, network_path) { + let receivers = if connector.input_index() == 0 { &mut siblings } else { &mut parents }; + receivers.push(node_id); + continue; + } + + // A node passes it on only when taking it as its primary input, rather than as a parameter + if connector.input_index() == 0 && visited_nodes.insert(node_id) { + pending_connectors.extend(outward_connectors(node_id)); + } + } + + // Sorted for a stable button order, since outward wires are unordered + siblings.sort_unstable(); + siblings.dedup(); + parents.sort_unstable(); + parents.dedup(); + + // The layer feeding this one from below in its stack, unless this is the bottom + let layer_below = node_inspector::input_chain(layer, 0, context.network_interface, network_path).and_then(|(_, stack_layer)| stack_layer); + + // Each is only referred to by a button, wired to the layer's section. Parents sit just above, the wire turning into their content, + // and siblings above them, the wire continuing up past that turn into their bottom. + let mut sections = Vec::new(); + + if let Some(siblings_section) = node_inspector::layer_references_section(&siblings, "Select Sibling Layer", context) { + sections.push(siblings_section); + } + if let Some(mut parents_section) = node_inspector::layer_references_section(&parents, "Select Parent Layer", context) { + if let LayoutGroup::NodeSection(section) = &mut parents_section { + section.content_wire = Some(node_inspector::output_section_wire(layer, context)); + section.content_wire_continues = !siblings.is_empty(); + } + sections.push(parents_section); + } + if !sections.is_empty() + && let LayoutGroup::NodeSection(section) = &mut layer_section + { + section.output_wire = Some(node_inspector::output_section_wire(layer, context)); + } + sections.push(layer_section); + if let Some(layer_below) = layer_below + && let Some(mut below_section) = node_inspector::layer_references_section(&[layer_below], "Select Sibling Layer", context) + { + if let LayoutGroup::NodeSection(section) = &mut below_section { + section.output_wire = Some(node_inspector::output_section_wire(layer_below, context)); + } + sections.push(below_section); + } + + sections } // If multiple layers and/or nodes are selected, show nothing _ => Vec::new(), diff --git a/editor/src/messages/portfolio/document/node_graph/node_inspector.rs b/editor/src/messages/portfolio/document/node_graph/node_inspector.rs index bca938a149..8468c351d3 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_inspector.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_inspector.rs @@ -3086,15 +3086,6 @@ pub(crate) fn rectangle_inspector(node_id: NodeId, context: &mut NodeInspectorCo ] } -pub(crate) fn node_no_inspector_content(node_id: NodeId, context: &mut NodeInspectorContext) -> Vec { - let text = if context.network_interface.is_layer(&node_id, context.selection_network_path) { - "Layer has no parameters" - } else { - "Node has no parameters" - }; - string_inspector(text) -} - pub(crate) fn generate_node_inspector(node_id: NodeId, context: &mut NodeInspectorContext) -> LayoutGroup { let mut layout = Vec::new(); @@ -3183,10 +3174,6 @@ pub(crate) fn generate_node_inspector(node_id: NodeId, context: &mut NodeInspect } } - if layout.is_empty() { - layout = node_no_inspector_content(node_id, context); - } - let display_name = context .network_interface .node_metadata(&node_id, context.selection_network_path) @@ -3237,16 +3224,12 @@ pub(crate) fn generate_node_inspector(node_id: NodeId, context: &mut NodeInspect } // That layer is only referred to, as in the Data panel, rather than shown with its own parameters and chain - if let Some(layer) = stack_layer { - let button = node_reference_button(layer, context.network_interface, network_path, network_path, move || { - NodeGraphMessage::SelectedNodesSet { nodes: vec![layer] }.into() - }); - let name = context.network_interface.display_name(&layer, network_path); - let visible = context.network_interface.is_visible(&layer, network_path); - - let mut reference_section = LayoutGroup::section(name, None, "", visible, false, true, layer.0, Layout(vec![LayoutGroup::row(vec![button])])); + let feeds_content = input_index == LAYER_SECONDARY_INPUT_INDEX && context.network_interface.is_layer(&node_id, network_path); + let tooltip_label = if feeds_content { "Select Child Layer" } else { "Select Layer" }; + if let Some(layer) = stack_layer + && let Some(mut reference_section) = layer_references_section(&[layer], tooltip_label, context) + { if let LayoutGroup::NodeSection(section) = &mut reference_section { - section.node_reference = true; section.output_wire = Some(output_section_wire(layer, context)); } @@ -3261,8 +3244,35 @@ pub(crate) fn generate_node_inspector(node_id: NodeId, context: &mut NodeInspect section } +/// A section only referring to layers, as the Data panel does, with a row of buttons that each select one rather than showing its parameters and chain. +/// Their tooltip label names how the layers relate to the section they're shown beside. +pub(crate) fn layer_references_section(layers: &[NodeId], tooltip_label: &str, context: &NodeInspectorContext) -> Option { + let network_path = context.selection_network_path; + let &first_layer = layers.first()?; + + let mut buttons = Vec::with_capacity(layers.len() * 2); + for &layer in layers { + if !buttons.is_empty() { + buttons.push(Separator::new(SeparatorStyle::Related).widget_instance()); + } + let button = node_reference_button(layer, context.network_interface, network_path, network_path, move || { + NodeGraphMessage::SelectedNodesSet { nodes: vec![layer] }.into() + }); + buttons.push(button.tooltip_label(tooltip_label).widget_instance()); + } + + let name = context.network_interface.display_name(&first_layer, network_path); + let visible = context.network_interface.is_visible(&first_layer, network_path); + + let mut section = LayoutGroup::section(name, None, "", visible, false, true, first_layer.0, Layout(vec![LayoutGroup::row(buttons)])); + if let LayoutGroup::NodeSection(node_section) = &mut section { + node_section.node_reference = true; + } + Some(section) +} + /// The wire drawn up from a node's section in a chain to the section above, which its output feeds. -fn output_section_wire(node_id: NodeId, context: &NodeInspectorContext) -> SectionWire { +pub(crate) fn output_section_wire(node_id: NodeId, context: &NodeInspectorContext) -> SectionWire { let output_type = context.network_interface.output_type(&OutputConnector::node(node_id, 0), context.selection_network_path); SectionWire { diff --git a/frontend/src/components/panels/Inspector.svelte b/frontend/src/components/panels/Inspector.svelte index 15bd9b6c9d..fdef1eece5 100644 --- a/frontend/src/components/panels/Inspector.svelte +++ b/frontend/src/components/panels/Inspector.svelte @@ -15,7 +15,7 @@ let dragging = false; let fromIndex: number | undefined = undefined; let insertIndex: number | undefined = undefined; - let insertMarkerTop: number | undefined = undefined; + let insertMarker: { top: number; left: number; width: number } | undefined = undefined; let justFinishedDrag = false; // Used to suppress the click event that follows a drag release (which would otherwise toggle a section) onMount(() => { @@ -91,7 +91,7 @@ const sections = reorderableSections(); if (!container || sections.length === 0) { insertIndex = undefined; - insertMarkerTop = undefined; + insertMarker = undefined; return; } @@ -111,17 +111,38 @@ // Position the marker purely from the gap index so it has one fixed spot per gap, rather than snapping between adjacent // sections' edges as the cursor crosses their shared boundary. + // Above the first, it's centered in the room left below what comes before, and below the last, in a gap as wide as the sections leave between each other + const halfGap = (parseFloat(getComputedStyle(sections[0]).getPropertyValue("--section-gap")) || 0) / 2; let markerViewportY; if (index <= 0) { - markerViewportY = sections[0].getBoundingClientRect().top - 2; + markerViewportY = (bottomOfContentAbove(sections[0], container) + sections[0].getBoundingClientRect().top) / 2; } else if (index >= sections.length) { - markerViewportY = sections[sections.length - 1].getBoundingClientRect().bottom + 2; + markerViewportY = sections[sections.length - 1].getBoundingClientRect().bottom + halfGap; } else { markerViewportY = (sections[index - 1].getBoundingClientRect().bottom + sections[index].getBoundingClientRect().top) / 2; } + // Spanning the sections, which a layer's frame around them indents + const firstRect = sections[0].getBoundingClientRect(); + insertIndex = index; - insertMarkerTop = toContentOffset(markerViewportY); + insertMarker = { top: toContentOffset(markerViewportY), left: firstRect.left - containerRect.left, width: firstRect.width }; + } + + // The bottom of what's shown right above a section, which is the last row or section before it (even outside the frame it's in), or else the top of the panel + function bottomOfContentAbove(section: Element, container: HTMLElement): number { + let current = section; + while (current !== container && current.parentElement) { + let previous = current.previousElementSibling; + if (previous) { + // Down through the frames and section bodies to the last row or section within + while (previous.lastElementChild && previous.hasAttribute("data-section-contents")) previous = previous.lastElementChild; + return previous.getBoundingClientRect().bottom; + } + + current = current.parentElement; + } + return container.getBoundingClientRect().top; } function draggingPointerUp(e: PointerEvent) { @@ -160,15 +181,15 @@ dragging = false; fromIndex = undefined; insertIndex = undefined; - insertMarkerTop = undefined; + insertMarker = undefined; } - {#if dragging && insertMarkerTop !== undefined} -
+ {#if dragging && insertMarker} +
{/if}
@@ -201,8 +222,6 @@ .insert-mark { position: absolute; - left: 4px; - right: 4px; background: var(--color-e-nearwhite); height: 5px; // The marker's `top` is the center of the gap, so shift up by half its height to straddle that line diff --git a/frontend/src/components/panels/Layers.svelte b/frontend/src/components/panels/Layers.svelte index 3cd6945754..43b60da6f6 100644 --- a/frontend/src/components/panels/Layers.svelte +++ b/frontend/src/components/panels/Layers.svelte @@ -1329,11 +1329,15 @@ background: rgb(from var(--color-4-dimgray) r g b / 0.5); } + // Spanning the insertion line beside the layer (past the visibility column and the indent), plus its own thickness outward so it clears the icons at both ends &.insert-folder::after { + --outline-thickness: 3px; content: ""; position: absolute; inset: 0; - border: 3px solid var(--color-e-nearwhite); + left: calc(24px + var(--layer-indent-levels) * 16px - var(--outline-thickness)); + right: calc(-1 * var(--outline-thickness)); + border: var(--outline-thickness) solid var(--color-e-nearwhite); border-radius: 2px; pointer-events: none; } @@ -1412,7 +1416,7 @@ } // The name (and lock) and the chain split the rest of the row evenly, except that either gives the other whatever share it doesn't need. - // Between them, the spacer keeps an unrelated-width gap. The right margin keeps the layer icon 4px from the row's end like the visibility icon at its start. + // Between them, the spacer keeps an unrelated-width gap. .layer-name-and-chain { flex: 1 1 0; min-width: 0; @@ -1420,7 +1424,6 @@ display: grid; grid-template-columns: minmax(0, max-content) auto minmax(4px, 1fr) minmax(0, var(--chain-width)); align-items: center; - margin-right: 2px; // While renaming, the name takes all the room its text needs, which the chain gives up until it disappears &.editing { @@ -1692,10 +1695,10 @@ margin: 0 8px; } - // At the row's end, past the layer icon's margin and the row's margin + // At the row's end, past a margin like the layer icon's .chain-node-icon { margin-left: auto; - margin-right: calc(2px + 2px); + margin-right: 2px; // Outlined like the layer icon when the active tool edits it &.tool-target, diff --git a/frontend/src/components/widgets/NodeSection.svelte b/frontend/src/components/widgets/NodeSection.svelte index 8dcefc8f5f..ea9442f641 100644 --- a/frontend/src/components/widgets/NodeSection.svelte +++ b/frontend/src/components/widgets/NodeSection.svelte @@ -16,8 +16,11 @@ export { className as class }; export let classes: Record = {}; + // A node without parameters has nothing to show, so its section stays collapsed with its arrow grayed out, like the Layers panel's + $: expandable = widgetData.layout.length > 0; + // Whether the section is expanded is owned by the backend (persisted per node), so just reflect it here - $: expanded = widgetData.expanded; + $: expanded = widgetData.expanded && expandable; // The sections of the chain feeding one of this node's inputs, which follow its own rows and are shown beneath them $: chainSections = widgetData.layout.flatMap((layoutGroup) => ("NodeSection" in layoutGroup && layoutGroup.NodeSection.outputWire ? [layoutGroup.NodeSection] : [])); @@ -30,6 +33,8 @@ // Like the Layers panel's expand arrows, a modifier key applies the toggle recursively to the sections nested within function toggleExpandedWithModifiers(e: MouseEvent) { + if (!expandable) return; + const accel = operatingSystem() === "Mac" ? e.metaKey : e.ctrlKey; editor.toggleNodeInspectorSectionExpanded(widgetData.id, e.altKey || accel); } @@ -45,42 +50,46 @@ "output-wire": Boolean(widgetData.outputWire), "output-wire-list": Boolean(widgetData.outputWire?.isList), "node-reference": widgetData.nodeReference, + "content-wire": Boolean(widgetData.contentWire), + "content-wire-list": Boolean(widgetData.contentWire?.isList), + "content-wire-continues": widgetData.contentWireContinues, collapsed: !expanded, }} styles={{ "--chain-wire-color": widgetData.chainWire && `var(--color-data-${widgetData.chainWire.dataType.toLowerCase()}-dim)`, "--output-wire-color": widgetData.outputWire && `var(--color-data-${widgetData.outputWire.dataType.toLowerCase()}-dim)`, + "--content-wire-color": widgetData.contentWire && `var(--color-data-${widgetData.contentWire.dataType.toLowerCase()}-dim)`, }} data-inspector-reorderable-section={reorderable ? "" : undefined} data-node-id={reorderable ? String(widgetData.id) : undefined} > {#if widgetData.nodeReference} + {#if widgetData.contentWireContinues} +
+ {/if} {#each widgetData.layout as layoutGroup} {#if "Row" in layoutGroup} {/if} {/each} {:else} - {#if expanded} - + {#each widgetData.layout as layoutGroup} {#if "Row" in layoutGroup} @@ -124,7 +136,7 @@ {/each} {#if chainSections.length > 0} - + {#each chainSections as chainSection} {/each} @@ -136,11 +148,32 @@