Skip to content

Commit 4250f29

Browse files
adamgerhantKeavon
andauthored
Add merging nodes into a subgraph with Ctrl+M and basic subgraph signature customization (#2097)
* Merge nodes * Fix bugs/crashes * WIP: Debugging * Fix bugs, add button * Add imports/exports * Improve button * Fix breadcrumbs * Fix lints and change shortcut key --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 4c4d559 commit 4250f29

File tree

13 files changed

+735
-238
lines changed

13 files changed

+735
-238
lines changed

editor/src/messages/frontend/frontend_message.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ pub enum FrontendMessage {
131131
UpdateImportsExports {
132132
imports: Vec<(FrontendGraphOutput, i32, i32)>,
133133
exports: Vec<(FrontendGraphInput, i32, i32)>,
134+
#[serde(rename = "addImport")]
135+
add_import: Option<(i32, i32)>,
136+
#[serde(rename = "addExport")]
137+
add_export: Option<(i32, i32)>,
134138
},
135139
UpdateInSelectedNetwork {
136140
#[serde(rename = "inSelectedNetwork")]

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub fn input_mappings() -> Mapping {
7575
entry!(KeyDown(KeyL); modifiers=[Alt], action_dispatch=NodeGraphMessage::ToggleSelectedAsLayersOrNodes),
7676
entry!(KeyDown(KeyC); modifiers=[Shift], action_dispatch=NodeGraphMessage::PrintSelectedNodeCoordinates),
7777
entry!(KeyDown(KeyC); modifiers=[Alt], action_dispatch=NodeGraphMessage::SendClickTargets),
78+
entry!(KeyDown(KeyM); modifiers=[Accel], action_dispatch=NodeGraphMessage::MergeSelectedNodes),
7879
entry!(KeyUp(KeyC); action_dispatch=NodeGraphMessage::EndSendClickTargets),
7980
entry!(KeyDown(ArrowUp); action_dispatch=NodeGraphMessage::ShiftSelectedNodes { direction: Direction::Up, rubber_band: false }),
8081
entry!(KeyDown(ArrowRight); action_dispatch=NodeGraphMessage::ShiftSelectedNodes { direction: Direction::Right, rubber_band: false }),

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
326326
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
327327
}
328328
DocumentMessage::DebugPrintDocument => {
329-
info!("{:#?}", self.network_interface);
329+
info!("{:?}", self.network_interface);
330330
}
331331
DocumentMessage::DeleteNode { node_id } => {
332332
responses.add(DocumentMessage::StartTransaction);
@@ -1128,6 +1128,9 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
11281128
// TODO: Allow non layer nodes to have click targets
11291129
let layer_click_targets = click_targets
11301130
.into_iter()
1131+
.filter(|(node_id, _)|
1132+
// Ensure that the layer is in the document network to prevent logging an error
1133+
self.network_interface.network(&[]).unwrap().nodes.contains_key(node_id))
11311134
.filter_map(|(node_id, click_targets)| {
11321135
self.network_interface.is_layer(&node_id, &[]).then(|| {
11331136
let layer = LayerNodeIdentifier::new(node_id, &self.network_interface, &[]);
@@ -1223,11 +1226,19 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
12231226
self.network_interface.set_transform(transform, &self.breadcrumb_network_path);
12241227
let imports = self.network_interface.frontend_imports(&self.breadcrumb_network_path).unwrap_or_default();
12251228
let exports = self.network_interface.frontend_exports(&self.breadcrumb_network_path).unwrap_or_default();
1229+
let add_import = self.network_interface.frontend_import_modify(&self.breadcrumb_network_path);
1230+
let add_export = self.network_interface.frontend_export_modify(&self.breadcrumb_network_path);
1231+
12261232
responses.add(DocumentMessage::RenderRulers);
12271233
responses.add(DocumentMessage::RenderScrollbars);
12281234
responses.add(NodeGraphMessage::UpdateEdges);
12291235
responses.add(NodeGraphMessage::UpdateBoxSelection);
1230-
responses.add(FrontendMessage::UpdateImportsExports { imports, exports });
1236+
responses.add(FrontendMessage::UpdateImportsExports {
1237+
imports,
1238+
exports,
1239+
add_import,
1240+
add_export,
1241+
});
12311242
responses.add(FrontendMessage::UpdateNodeGraphTransform {
12321243
transform: Transform {
12331244
scale: transform.matrix2.x_axis.x,

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ static DOCUMENT_NODE_TYPES: once_cell::sync::Lazy<Vec<DocumentNodeDefinition>> =
6464
/// The [`DocumentNode`] is the instance while these [`DocumentNodeDefinition`]s are the "classes" or "blueprints" from which the instances are built.
6565
fn static_nodes() -> Vec<DocumentNodeDefinition> {
6666
let mut custom = vec![
67+
// TODO: Auto-generate this from its proto node macro
68+
DocumentNodeDefinition {
69+
identifier: "Default Network",
70+
category: "General",
71+
node_template: NodeTemplate {
72+
document_node: DocumentNode {
73+
implementation: DocumentNodeImplementation::Network(NodeNetwork::default()),
74+
..Default::default()
75+
},
76+
persistent_node_metadata: DocumentNodePersistentMetadata {
77+
network_metadata: Some(NodeNetworkMetadata::default()),
78+
..Default::default()
79+
},
80+
},
81+
description: Cow::Borrowed("A default node network you can use to create your own custom nodes."),
82+
properties: &node_properties::node_no_properties,
83+
},
6784
// TODO: Auto-generate this from its proto node macro
6885
DocumentNodeDefinition {
6986
identifier: "Identity",
@@ -80,7 +97,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
8097
..Default::default()
8198
},
8299
},
83-
description: Cow::Borrowed("The identity node simply passes its data through. You can use this to organize your node graph if you want."),
100+
description: Cow::Borrowed("The identity node passes its data through. You can use this to organize your node graph."),
84101
properties: &|_document_node, _node_id, _context| node_properties::string_properties("The identity node simply passes its data through"),
85102
},
86103
// TODO: Auto-generate this from its proto node macro
@@ -101,7 +118,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
101118
..Default::default()
102119
},
103120
},
104-
description: Cow::Borrowed("The Monitor node is used by the editor to access the data flowing through it"),
121+
description: Cow::Borrowed("The Monitor node is used by the editor to access the data flowing through it."),
105122
properties: &|_document_node, _node_id, _context| node_properties::string_properties("The Monitor node is used by the editor to access the data flowing through it"),
106123
},
107124
DocumentNodeDefinition {
@@ -208,7 +225,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
208225
..Default::default()
209226
},
210227
},
211-
description: Cow::Borrowed("The Merge node combines graphical data through composition"),
228+
description: Cow::Borrowed("The Merge node combines graphical data through composition."),
212229
properties: &node_properties::node_no_properties,
213230
},
214231
DocumentNodeDefinition {
@@ -319,7 +336,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
319336
..Default::default()
320337
},
321338
},
322-
description: Cow::Borrowed("Creates a new Artboard which can be used as a working surface"),
339+
description: Cow::Borrowed("Creates a new Artboard which can be used as a working surface."),
323340
properties: &node_properties::artboard_properties,
324341
},
325342
DocumentNodeDefinition {
@@ -719,7 +736,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
719736
..Default::default()
720737
},
721738
},
722-
description: Cow::Borrowed("Creates an embedded image with the given transform"),
739+
description: Cow::Borrowed("Creates an embedded image with the given transform."),
723740
properties: &|_document_node, _node_id, _context| node_properties::string_properties("Creates an embedded image with the given transform"),
724741
},
725742
DocumentNodeDefinition {
@@ -798,7 +815,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
798815
..Default::default()
799816
},
800817
},
801-
description: Cow::Borrowed("Generates different noise patters"),
818+
description: Cow::Borrowed("Generates different noise patterns."),
802819
properties: &node_properties::noise_pattern_properties,
803820
},
804821
// TODO: This needs to work with resolution-aware (raster with footprint, post-Cull node) data.

editor/src/messages/portfolio/document/node_graph/node_graph_message.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye
44
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeTemplate, OutputConnector};
55
use crate::messages::prelude::*;
66

7+
use glam::IVec2;
78
use graph_craft::document::value::TaggedValue;
89
use graph_craft::document::{NodeId, NodeInput};
910
use graph_craft::proto::GraphErrors;
@@ -16,6 +17,8 @@ pub enum NodeGraphMessage {
1617
nodes: Vec<(NodeId, NodeTemplate)>,
1718
new_ids: HashMap<NodeId, NodeId>,
1819
},
20+
AddImport,
21+
AddExport,
1922
Init,
2023
SelectedNodesUpdated,
2124
Copy,
@@ -68,6 +71,7 @@ pub enum NodeGraphMessage {
6871
input_connector: InputConnector,
6972
insert_node_input_index: usize,
7073
},
74+
MergeSelectedNodes,
7175
MoveLayerToStack {
7276
layer: LayerNodeIdentifier,
7377
parent: LayerNodeIdentifier,
@@ -126,19 +130,23 @@ pub enum NodeGraphMessage {
126130
node_id: NodeId,
127131
alias: String,
128132
},
133+
SetToNodeOrLayer {
134+
node_id: NodeId,
135+
is_layer: bool,
136+
},
129137
ShiftNodePosition {
130138
node_id: NodeId,
131139
x: i32,
132140
y: i32,
133141
},
134-
SetToNodeOrLayer {
135-
node_id: NodeId,
136-
is_layer: bool,
137-
},
138142
ShiftSelectedNodes {
139143
direction: Direction,
140144
rubber_band: bool,
141145
},
146+
ShiftSelectedNodesByAmount {
147+
graph_delta: IVec2,
148+
rubber_band: bool,
149+
},
142150
TogglePreview {
143151
node_id: NodeId,
144152
},

0 commit comments

Comments
 (0)