From 81f365c9991d36a81e2159148dc33d073ea9492d Mon Sep 17 00:00:00 2001 From: 0HyperCube <78500760+0HyperCube@users.noreply.github.com> Date: Wed, 21 Dec 2022 11:12:33 +0000 Subject: [PATCH] Show all nodes with no selection (#893) * Show all nodes with no selection * Slight text tweaks * Rename to artwork Co-authored-by: Keavon Chambers --- Cargo.lock | 1 + .../node_graph/node_graph_message_handler.rs | 23 ++++++++++++++---- .../document_node_types.rs | 4 ++-- .../properties_panel/utility_functions.rs | 24 ++++++++----------- libraries/dyn-any/derive/Cargo.toml | 3 +++ 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da068a73..57b0b4df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -905,6 +905,7 @@ dependencies = [ name = "dyn-any-derive" version = "0.2.1" dependencies = [ + "dyn-any", "proc-macro2", "quote", "syn", 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 8f77c562..600ebb3d 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 @@ -157,22 +157,35 @@ impl NodeGraphMessageHandler { ); } - pub fn collate_properties(&self, node_graph_frame: &NodeGraphFrameLayer, context: &mut NodePropertiesContext) -> Vec { + pub fn collate_properties(&self, node_graph_frame: &NodeGraphFrameLayer, context: &mut NodePropertiesContext, sections: &mut Vec) { let mut network = &node_graph_frame.network; for segement in &self.nested_path { network = network.nodes.get(segement).and_then(|node| node.implementation.get_network()).unwrap(); } - let mut section = Vec::new(); + // If empty, show all nodes in the network starting with the output + if self.selected_nodes.is_empty() { + let mut stack = vec![network.output]; + let mut nodes = Vec::new(); + while let Some(node_id) = stack.pop() { + let Some(document_node) = network.nodes.get(&node_id) else { + continue; + }; + + stack.extend(document_node.inputs.iter().filter_map(|input| if let NodeInput::Node(ref_id) = input { Some(*ref_id) } else { None })); + nodes.push((document_node, node_id)); + } + for &(document_node, node_id) in nodes.iter().rev() { + sections.push(node_properties::generate_node_properties(document_node, node_id, context)); + } + } for node_id in &self.selected_nodes { let Some(document_node) = network.nodes.get(node_id) else { continue; }; - section.push(node_properties::generate_node_properties(document_node, *node_id, context)); + sections.push(node_properties::generate_node_properties(document_node, *node_id, context)); } - - section } fn send_graph(network: &NodeNetwork, responses: &mut VecDeque) { diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs index 143d1a3a..7e55a571 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs @@ -73,7 +73,7 @@ static DOCUMENT_NODE_TYPES: &[DocumentNodeType] = &[ default: NodeInput::Network, }], outputs: &[FrontendGraphDataType::Raster], - properties: |_document_node, _node_id, _context| node_properties::string_properties("The input to the graph is the bitmap under the frame".to_string()), + properties: |_document_node, _node_id, _context| node_properties::string_properties("The graph's input is the artwork under the frame layer".to_string()), }, DocumentNodeType { name: "Output", @@ -85,7 +85,7 @@ static DOCUMENT_NODE_TYPES: &[DocumentNodeType] = &[ default: NodeInput::value(TaggedValue::Image(Image::empty()), true), }], outputs: &[], - properties: |_document_node, _node_id, _context| node_properties::string_properties("The output to the graph is rendered in the frame".to_string()), + properties: |_document_node, _node_id, _context| node_properties::string_properties("The graph's output is rendered into the frame".to_string()), }, DocumentNodeType { name: "Grayscale", diff --git a/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs b/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs index c6e3b8ef..c32a2b64 100644 --- a/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs +++ b/editor/src/messages/portfolio/document/properties_panel/utility_functions.rs @@ -291,21 +291,17 @@ pub fn register_artwork_layer_properties( vec![node_section_transform(layer, persistent_data)] } LayerDataType::NodeGraphFrame(node_graph_frame) => { - let is_graph_open = node_graph_message_handler.layer_path.as_ref().filter(|node_graph| *node_graph == &layer_path).is_some(); - let selected_nodes = &node_graph_message_handler.selected_nodes; - let mut properties_sections = vec![node_section_transform(layer, persistent_data)]; - if !selected_nodes.is_empty() && is_graph_open { - let mut context = crate::messages::portfolio::document::node_graph::NodePropertiesContext { - persistent_data, - document, - responses, - nested_path: &node_graph_message_handler.nested_path, - layer_path: &layer_path, - }; - let parameters_sections = node_graph_message_handler.collate_properties(node_graph_frame, &mut context); - properties_sections.extend(parameters_sections.into_iter()); - } + + let mut context = crate::messages::portfolio::document::node_graph::NodePropertiesContext { + persistent_data, + document, + responses, + nested_path: &node_graph_message_handler.nested_path, + layer_path: &layer_path, + }; + node_graph_message_handler.collate_properties(node_graph_frame, &mut context, &mut properties_sections); + properties_sections } LayerDataType::Folder(_) => { diff --git a/libraries/dyn-any/derive/Cargo.toml b/libraries/dyn-any/derive/Cargo.toml index 36488521..d4e357cc 100644 --- a/libraries/dyn-any/derive/Cargo.toml +++ b/libraries/dyn-any/derive/Cargo.toml @@ -17,3 +17,6 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = { version = "1", default-features = false, features = ["derive", "parsing", "proc-macro", "printing"] } + +[dev-dependencies] +dyn-any = { path = "..", features = ["derive"] }