Skip to content

Commit 69ed80b

Browse files
authored
Add ::IDENTITY to node macro to return a ProtoNodeIdentifier that is always a &'static str (#2842)
* fix warnings on master * make the `ProtoNodeIdentifier` of a Node be accessible and always a borrowed `&'static str` * always generate `node_name::identifier()`, even with `skip_impl` * make `FrontendNodeType` use Cow * remove broken `DocumentNodeDefinition`s for old GPU nodes * don't reexport `graphic_element` in it's entirety, only data structures * adjust everything to use the new `node_name::identifier()` * fixup imports for wasm * turn identifier fn into a constant
1 parent 4a83067 commit 69ed80b

File tree

20 files changed

+211
-521
lines changed

20 files changed

+211
-521
lines changed

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

Lines changed: 65 additions & 394 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec
2121
};
2222
}
2323

24-
let node_registry = graphene_core::registry::NODE_REGISTRY.lock().unwrap();
24+
let node_registry = NODE_REGISTRY.lock().unwrap();
2525
'outer: for (id, metadata) in NODE_METADATA.lock().unwrap().iter() {
2626
for node in custom.iter() {
2727
let DocumentNodeDefinition {
@@ -32,7 +32,7 @@ pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec
3232
..
3333
} = node;
3434
match implementation {
35-
DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier { name }) if name == id => continue 'outer,
35+
DocumentNodeImplementation::ProtoNode(name) if name == id => continue 'outer,
3636
_ => (),
3737
}
3838
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
14361436
if let Some(field) = graphene_std::registry::NODE_METADATA
14371437
.lock()
14381438
.unwrap()
1439-
.get(&proto_node_identifier.name.clone().into_owned())
1439+
.get(&proto_node_identifier)
14401440
.and_then(|metadata| metadata.fields.get(input_index))
14411441
{
14421442
number_options = (field.number_min, field.number_max, field.number_mode_range);

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::messages::portfolio::document::utility_types::network_interface::{Inp
22
use graph_craft::document::NodeId;
33
use graph_craft::document::value::TaggedValue;
44
use graphene_std::Type;
5+
use std::borrow::Cow;
56

67
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
78
pub enum FrontendGraphDataType {
@@ -98,33 +99,25 @@ pub struct FrontendNode {
9899

99100
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
100101
pub struct FrontendNodeType {
101-
pub name: String,
102-
pub category: String,
102+
pub name: Cow<'static, str>,
103+
pub category: Cow<'static, str>,
103104
#[serde(rename = "inputTypes")]
104-
pub input_types: Option<Vec<String>>,
105+
pub input_types: Option<Vec<Cow<'static, str>>>,
105106
}
106107

107108
impl FrontendNodeType {
108-
pub fn new(name: &'static str, category: &'static str) -> Self {
109+
pub fn new(name: impl Into<Cow<'static, str>>, category: impl Into<Cow<'static, str>>) -> Self {
109110
Self {
110-
name: name.to_string(),
111-
category: category.to_string(),
111+
name: name.into(),
112+
category: category.into(),
112113
input_types: None,
113114
}
114115
}
115116

116-
pub fn with_input_types(name: &'static str, category: &'static str, input_types: Vec<String>) -> Self {
117-
Self {
118-
name: name.to_string(),
119-
category: category.to_string(),
120-
input_types: Some(input_types),
121-
}
122-
}
123-
124-
pub fn with_owned_strings_and_input_types(name: String, category: String, input_types: Vec<String>) -> Self {
117+
pub fn with_input_types(name: impl Into<Cow<'static, str>>, category: impl Into<Cow<'static, str>>, input_types: Vec<Cow<'static, str>>) -> Self {
125118
Self {
126-
name,
127-
category,
119+
name: name.into(),
120+
category: category.into(),
128121
input_types: Some(input_types),
129122
}
130123
}

editor/src/messages/tool/common_functionality/graph_modification_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use crate::messages::portfolio::document::utility_types::network_interface::{Flo
55
use crate::messages::prelude::*;
66
use bezier_rs::Subpath;
77
use glam::DVec2;
8-
use graph_craft::concrete;
98
use graph_craft::document::value::TaggedValue;
109
use graph_craft::document::{NodeId, NodeInput};
10+
use graph_craft::{ProtoNodeIdentifier, concrete};
1111
use graphene_std::Color;
1212
use graphene_std::NodeInputDecleration;
1313
use graphene_std::raster::BlendMode;
@@ -416,14 +416,14 @@ impl<'a> NodeGraphLayer<'a> {
416416
}
417417

418418
/// Node id of a protonode if it exists in the layer's primary flow
419-
pub fn upstream_node_id_from_protonode(&self, protonode_identifier: &'static str) -> Option<NodeId> {
419+
pub fn upstream_node_id_from_protonode(&self, protonode_identifier: ProtoNodeIdentifier) -> Option<NodeId> {
420420
self.horizontal_layer_flow()
421421
// Take until a different layer is reached
422422
.take_while(|&node_id| node_id == self.layer_node || !self.network_interface.is_layer(&node_id, &[]))
423-
.find(move |node_id| {
423+
.find(|node_id| {
424424
self.network_interface
425425
.implementation(node_id, &[])
426-
.is_some_and(move |implementation| *implementation == graph_craft::document::DocumentNodeImplementation::proto(protonode_identifier))
426+
.is_some_and(|implementation| *implementation == graph_craft::document::DocumentNodeImplementation::ProtoNode(protonode_identifier.clone()))
427427
})
428428
}
429429

editor/src/messages/tool/common_functionality/shapes/ellipse_shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ mod test_ellipse {
7777
layers
7878
.filter_map(|layer| {
7979
let node_graph_layer = NodeGraphLayer::new(layer, &document.network_interface);
80-
let ellipse_node = node_graph_layer.upstream_node_id_from_protonode(ellipse::protonode_identifier())?;
80+
let ellipse_node = node_graph_layer.upstream_node_id_from_protonode(ellipse::IDENTIFIER)?;
8181
Some(ResolvedEllipse {
8282
radius_x: instrumented.grab_protonode_input::<ellipse::RadiusXInput>(&vec![ellipse_node], &editor.runtime).unwrap(),
8383
radius_y: instrumented.grab_protonode_input::<ellipse::RadiusYInput>(&vec![ellipse_node], &editor.runtime).unwrap(),

editor/src/messages/tool/tool_messages/artboard_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ mod test_artboard {
567567
Ok(instrumented) => instrumented,
568568
Err(e) => panic!("Failed to evaluate graph: {}", e),
569569
};
570-
instrumented.grab_all_input::<graphene_std::append_artboard::ArtboardInput>(&editor.runtime).collect()
570+
instrumented.grab_all_input::<graphene_std::graphic_element::append_artboard::ArtboardInput>(&editor.runtime).collect()
571571
}
572572

573573
#[tokio::test]

editor/src/node_graph_executor.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ mod test {
413413
use super::*;
414414
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
415415
use crate::test_utils::test_prelude::{self, NodeGraphLayer};
416+
use graph_craft::ProtoNodeIdentifier;
416417
use graph_craft::document::NodeNetwork;
417418
use graphene_std::Context;
418419
use graphene_std::NodeInputDecleration;
@@ -422,7 +423,7 @@ mod test {
422423
/// Stores all of the monitor nodes that have been attached to a graph
423424
#[derive(Default)]
424425
pub struct Instrumented {
425-
protonodes_by_name: HashMap<String, Vec<Vec<Vec<NodeId>>>>,
426+
protonodes_by_name: HashMap<ProtoNodeIdentifier, Vec<Vec<Vec<NodeId>>>>,
426427
protonodes_by_path: HashMap<Vec<NodeId>, Vec<Vec<NodeId>>>,
427428
}
428429

@@ -449,15 +450,15 @@ mod test {
449450
}
450451
if let DocumentNodeImplementation::ProtoNode(identifier) = &mut node.implementation {
451452
path.push(*id);
452-
self.protonodes_by_name.entry(identifier.name.to_string()).or_default().push(monitor_node_ids.clone());
453+
self.protonodes_by_name.entry(identifier.clone()).or_default().push(monitor_node_ids.clone());
453454
self.protonodes_by_path.insert(path.clone(), monitor_node_ids);
454455
path.pop();
455456
}
456457
}
457458
for (input, monitor_id) in monitor_nodes {
458459
let monitor_node = DocumentNode {
459460
inputs: vec![input],
460-
implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode"),
461+
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::memo::monitor::IDENTIFIER),
461462
manual_composition: Some(graph_craft::generic!(T)),
462463
skip_deduplication: true,
463464
..Default::default()
@@ -495,7 +496,7 @@ mod test {
495496
Input::Result: Send + Sync + Clone + 'static,
496497
{
497498
self.protonodes_by_name
498-
.get(Input::identifier())
499+
.get(&Input::identifier())
499500
.map_or([].as_slice(), |x| x.as_slice())
500501
.iter()
501502
.filter_map(|inputs| inputs.get(Input::INDEX))

editor/src/node_graph_executor/runtime.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::*;
22
use crate::messages::frontend::utility_types::{ExportBounds, FileType};
33
use glam::{DAffine2, DVec2};
4-
use graph_craft::concrete;
54
use graph_craft::document::value::TaggedValue;
65
use graph_craft::document::{NodeId, NodeNetwork};
76
use graph_craft::graphene_compiler::Compiler;
87
use graph_craft::proto::GraphErrors;
98
use graph_craft::wasm_application_io::EditorPreferences;
9+
use graph_craft::{ProtoNodeIdentifier, concrete};
1010
use graphene_std::Context;
1111
use graphene_std::application_io::{NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
1212
use graphene_std::instances::Instance;
@@ -46,7 +46,7 @@ pub struct NodeRuntime {
4646
inspect_state: Option<InspectState>,
4747

4848
/// Mapping of the fully-qualified node paths to their preprocessor substitutions.
49-
substitutions: HashMap<String, DocumentNode>,
49+
substitutions: HashMap<ProtoNodeIdentifier, DocumentNode>,
5050

5151
// TODO: Remove, it doesn't need to be persisted anymore
5252
/// The current renders of the thumbnails for layer nodes.
@@ -435,7 +435,7 @@ impl InspectState {
435435

436436
let monitor_node = DocumentNode {
437437
inputs: vec![NodeInput::node(inspect_node, 0)], // Connect to the primary output of the inspect node
438-
implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode"),
438+
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::memo::monitor::IDENTIFIER),
439439
manual_composition: Some(graph_craft::generic!(T)),
440440
skip_deduplication: true,
441441
..Default::default()

frontend/src-tauri/src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
use axum::routing::get;
44
use axum::Router;
55
use fern::colors::{Color, ColoredLevelConfig};
6-
use graphite_editor::application::Editor;
7-
use graphite_editor::messages::prelude::*;
8-
use graphite_editor::node_graph_executor::GraphRuntimeRequest;
9-
use graphite_editor::node_graph_executor::NODE_RUNTIME;
106
use graphite_editor::node_graph_executor::*;
117
use std::sync::Mutex;
128

0 commit comments

Comments
 (0)