Skip to content

Commit 8efa74d

Browse files
committed
Render default document
1 parent db6a7ce commit 8efa74d

File tree

8 files changed

+266
-100
lines changed

8 files changed

+266
-100
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::node_graph::utility_types::Transform;
22
use super::utility_types::clipboards::Clipboard;
33
use super::utility_types::error::EditorError;
44
use super::utility_types::misc::{BoundingBoxSnapTarget, GeometrySnapTarget, OptionBoundsSnapping, OptionPointSnapping, SnappingOptions, SnappingState};
5-
use super::utility_types::network_interface::{InputConnector, NodeNetworkInterface};
5+
use super::utility_types::network_interface::{self, InputConnector, NodeNetworkInterface};
66
use super::utility_types::nodes::{CollapsedLayers, SelectedNodes};
77
use crate::application::{generate_uuid, GRAPHITE_GIT_COMMIT_HASH};
88
use crate::consts::{ASYMPTOTIC_EFFECT, DEFAULT_DOCUMENT_NAME, FILE_SAVE_SUFFIX, SCALE_EFFECT, SCROLLBAR_SPACING, VIEWPORT_ROTATE_SNAP_INTERVAL};
@@ -123,7 +123,7 @@ impl Default for DocumentMessageHandler {
123123
// ============================================
124124
// Fields that are saved in the document format
125125
// ============================================
126-
network_interface: Default::default(),
126+
network_interface: default_document_network_interface(),
127127
selected_nodes: SelectedNodes::default(),
128128
collapsed: CollapsedLayers::default(),
129129
name: DEFAULT_DOCUMENT_NAME.to_string(),
@@ -407,7 +407,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
407407
});
408408

409409
// Group all shallowest unique selected layers in order
410-
let mut all_layers_to_group = self
410+
let all_layers_to_group = self
411411
.network_interface
412412
.shallowest_unique_layers(self.selected_nodes.selected_layers(self.metadata()))
413413
.collect::<Vec<_>>();
@@ -1945,13 +1945,9 @@ impl DocumentMessageHandler {
19451945
}
19461946
}
19471947

1948-
fn root_network() -> NodeNetwork {
1949-
{
1950-
let mut network = NodeNetwork::default();
1951-
network.exports = vec![NodeInput::Value {
1952-
tagged_value: TaggedValue::ArtboardGroup(graphene_core::ArtboardGroup::EMPTY),
1953-
exposed: true,
1954-
}];
1955-
network
1956-
}
1948+
/// Create a network interface with a single export
1949+
fn default_document_network_interface() -> NodeNetworkInterface {
1950+
let mut network_interface = NodeNetworkInterface::default();
1951+
network_interface.add_export(TaggedValue::ArtboardGroup(graphene_core::ArtboardGroup::EMPTY), -1, "".to_string(), true);
1952+
network_interface
19571953
}

editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use super::transform_utils;
22
use super::utility_types::ModifyInputsContext;
3-
use crate::messages::portfolio::document::utility_types::document_metadata::{ LayerNodeIdentifier};
4-
use crate::messages::portfolio::document::utility_types::network_interface::{
5-
InputConnector, NodeNetworkInterface, NodeTypePersistentMetadata,
6-
};
3+
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
4+
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface, NodeTypePersistentMetadata};
75
use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers, SelectedNodes};
86
use crate::messages::prelude::*;
97

@@ -33,8 +31,8 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for Gr
3331
let GraphOperationMessageData {
3432
network_interface,
3533
selected_nodes,
36-
collapsed,
37-
node_graph,
34+
collapsed: _,
35+
node_graph: _,
3836
} = data;
3937

4038
match message {
@@ -425,7 +423,6 @@ fn import_usvg_node(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node,
425423
.unwrap_or_default();
426424
modify_inputs.insert_vector_data(subpaths, layer);
427425

428-
let insert_index = if insert_index < 0 { 0 } else { insert_index as usize };
429426
modify_inputs.network_interface.move_layer_to_stack(layer, parent, insert_index);
430427

431428
if let Some(transform_node_id) = modify_inputs.get_existing_node_id("Transform") {

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::transform_utils;
2-
use crate::messages::portfolio::document::node_graph::document_node_types::{resolve_document_node_type};
3-
use crate::messages::portfolio::document::utility_types::document_metadata::{LayerNodeIdentifier};
2+
use crate::messages::portfolio::document::node_graph::document_node_types::resolve_document_node_type;
3+
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
44
use crate::messages::portfolio::document::utility_types::network_interface::{self, InputConnector, NodeNetworkInterface, NodeTemplate, OutputConnector};
55
use crate::messages::prelude::*;
66

77
use bezier_rs::Subpath;
88
use graph_craft::document::value::TaggedValue;
9-
use graph_craft::document::{generate_uuid,NodeId, NodeInput};
9+
use graph_craft::document::{generate_uuid, NodeId, NodeInput};
1010
use graphene_core::raster::{BlendMode, ImageFrame};
1111
use graphene_core::text::Font;
1212
use graphene_core::vector::brush_stroke::BrushStroke;
@@ -65,8 +65,6 @@ impl<'a> ModifyInputsContext<'a> {
6565
/// -> Layer3
6666
/// if insert_index == 3, return (Layer3, None)
6767
pub fn get_post_node_with_index(network_interface: &NodeNetworkInterface, parent: LayerNodeIdentifier, insert_index: usize) -> (InputConnector, Option<OutputConnector>) {
68-
let document_network = network_interface.document_network();
69-
7068
let mut post_node_input_connector = if parent == LayerNodeIdentifier::ROOT_PARENT {
7169
InputConnector::Export(0)
7270
} else {
@@ -168,11 +166,11 @@ impl<'a> ModifyInputsContext<'a> {
168166
let stroke_id = NodeId(generate_uuid());
169167
self.insert_node_to_chain(stroke_id, layer, stroke);
170168
let fill_id = NodeId(generate_uuid());
171-
self.insert_node_to_chain(stroke_id, layer, fill);
169+
self.insert_node_to_chain(fill_id, layer, fill);
172170
let transform_id = NodeId(generate_uuid());
173-
self.insert_node_to_chain(stroke_id, layer, transform);
171+
self.insert_node_to_chain(transform_id, layer, transform);
174172
let shape_id = NodeId(generate_uuid());
175-
self.insert_node_to_chain(stroke_id, layer, shape);
173+
self.insert_node_to_chain(shape_id, layer, shape);
176174
}
177175

178176
pub fn insert_text(&mut self, text: String, font: Font, size: f64, layer: LayerNodeIdentifier) {
@@ -189,9 +187,9 @@ impl<'a> ModifyInputsContext<'a> {
189187
let stroke_id = NodeId(generate_uuid());
190188
self.insert_node_to_chain(stroke_id, layer, stroke);
191189
let fill_id = NodeId(generate_uuid());
192-
self.insert_node_to_chain(stroke_id, layer, fill);
190+
self.insert_node_to_chain(fill_id, layer, fill);
193191
let transform_id = NodeId(generate_uuid());
194-
self.insert_node_to_chain(stroke_id, layer, transform);
192+
self.insert_node_to_chain(transform_id, layer, transform);
195193
let text_id = NodeId(generate_uuid());
196194
self.insert_node_to_chain(text_id, layer, text);
197195
self.responses.add(NodeGraphMessage::RunDocumentGraph);

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

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use super::node_properties;
2-
use super::utility_types::{FrontendNodeType};
2+
use super::utility_types::FrontendNodeType;
33
use crate::messages::layout::utility_types::widget_prelude::*;
44
use crate::messages::portfolio::document::utility_types::network_interface::{
5-
DocumentNodeMetadata, DocumentNodePersistentMetadata, NodeNetworkInterface, NodeNetworkMetadata,
6-
NodeNetworkPersistentMetadata, NodeTemplate, NodeTypePersistentMetadata,
5+
DocumentNodeMetadata, DocumentNodePersistentMetadata, NodeNetworkInterface, NodeNetworkMetadata, NodeNetworkPersistentMetadata, NodeTemplate, NodeTypePersistentMetadata,
76
};
87
use crate::messages::portfolio::utility_types::PersistentData;
98
use crate::messages::prelude::Message;
@@ -840,10 +839,10 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
840839
node_template: NodeTemplate {
841840
document_node: DocumentNode {
842841
implementation: DocumentNodeImplementation::Network(NodeNetwork {
843-
exports: vec![NodeInput::node(NodeId(3), 0)],
842+
exports: vec![NodeInput::node(NodeId(2), 0)],
844843
nodes: [
845844
DocumentNode {
846-
inputs: vec![NodeInput::network(concrete!(WasmEditorApi), 1)],
845+
inputs: vec![NodeInput::network(concrete!(&WasmEditorApi), 1)],
847846
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::CreateSurfaceNode")),
848847
skip_deduplication: true,
849848
..Default::default()
@@ -854,14 +853,19 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
854853
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
855854
..Default::default()
856855
},
856+
// TODO: Add conversion step
857+
// DocumentNode {
858+
// inputs: vec![NodeInput::network(graphene_core::Type::Fn(Box::new(concrete!(Footprint)), Box::new(generic!(T))), 0)],
859+
// implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, GraphicGroup>")),
860+
// ..Default::default()
861+
// },
857862
DocumentNode {
858-
inputs: vec![NodeInput::network(graphene_core::Type::Fn(Box::new(concrete!(Footprint)), Box::new(generic!(T))), 0)],
859-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, GraphicGroup>")),
860-
..Default::default()
861-
},
862-
DocumentNode {
863-
inputs: vec![NodeInput::network(concrete!(WasmEditorApi), 1), NodeInput::node(NodeId(2), 0), NodeInput::node(NodeId(1), 0)],
864-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::RenderNode<_, _>")),
863+
inputs: vec![
864+
NodeInput::network(concrete!(WasmEditorApi), 1),
865+
NodeInput::network(graphene_core::Type::Fn(Box::new(concrete!(Footprint)), Box::new(generic!(T))), 0),
866+
NodeInput::node(NodeId(1), 0),
867+
],
868+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::RenderNode<_, _, _>")),
865869
..Default::default()
866870
},
867871
]
@@ -880,7 +884,42 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
880884
persistent_node_metadata: DocumentNodePersistentMetadata {
881885
input_names: vec!["Output".to_string(), "In".to_string()],
882886
output_names: vec![],
883-
network_metadata: Some(NodeNetworkMetadata::default()),
887+
network_metadata: Some(NodeNetworkMetadata {
888+
persistent_metadata: NodeNetworkPersistentMetadata {
889+
node_metadata: [
890+
DocumentNodeMetadata {
891+
persistent_metadata: DocumentNodePersistentMetadata {
892+
display_name: "Create Canvas".to_string(),
893+
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
894+
..Default::default()
895+
},
896+
..Default::default()
897+
},
898+
DocumentNodeMetadata {
899+
persistent_metadata: DocumentNodePersistentMetadata {
900+
display_name: "Cache".to_string(),
901+
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
902+
..Default::default()
903+
},
904+
..Default::default()
905+
},
906+
DocumentNodeMetadata {
907+
persistent_metadata: DocumentNodePersistentMetadata {
908+
display_name: "RenderNode".to_string(),
909+
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
910+
..Default::default()
911+
},
912+
..Default::default()
913+
},
914+
]
915+
.into_iter()
916+
.enumerate()
917+
.map(|(id, node)| (NodeId(id as u64), node))
918+
.collect(),
919+
..Default::default()
920+
},
921+
..Default::default()
922+
}),
884923
..Default::default()
885924
},
886925
},
@@ -4416,7 +4455,7 @@ impl DocumentNodeDefinition {
44164455
input_override.into_iter().enumerate().for_each(|(index, input_override)| {
44174456
if let Some(input_override) = input_override {
44184457
// Only value inputs can be overridden, since node inputs change graph structure and must be handled by the network interface
4419-
assert!(matches!(input_override, NodeInput::Value { .. }), "Only value inputs are supported for input overrides");
4458+
// assert!(matches!(input_override, NodeInput::Value { .. }), "Only value inputs are supported for input overrides");
44204459
template.document_node.inputs[index] = input_override;
44214460
}
44224461
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ impl NodeGraphMessageHandler {
15421542
// Get import/export names from parent node metadata input/outputs, which must match the number of imports/exports.
15431543
// Empty string or no entry means to use type, or "Import/Export + index" if type can't be determined
15441544
// TODO: Get number of imports from parent node metadata
1545-
let (import_names, mut export_names) = if let Some(encapsulating_metadata) = network_interface.encapsulating_node_metadata() {
1545+
let (import_names, mut export_names) = if let Some(encapsulating_metadata) = network_interface.get_encapsulating_node_metadata() {
15461546
// Get all import/export names from encapsulating node metadata
15471547
(
15481548
encapsulating_metadata.persistent_metadata.input_names.clone(),

0 commit comments

Comments
 (0)