Node macro lambda parameters (#1309)

* Implement parsing of impl Node<I, …> syntax for the macro

* Extend node macro to allow specifying lambda nodes
This commit is contained in:
Dennis Kobert
2023-06-09 16:43:46 +02:00
committed by GitHub
parent 6ee9e20e4c
commit cf1d294013
15 changed files with 109 additions and 106 deletions

View File

@@ -95,8 +95,6 @@ pub enum FrontendMessage {
layer_path: Vec<LayerId>,
svg: String,
size: glam::DVec2,
#[serde(rename = "imaginateNodePath")]
imaginate_node_path: Option<Vec<NodeId>>,
},
TriggerRefreshBoundsOfViewports,
TriggerRevokeBlobUrl {

View File

@@ -96,7 +96,6 @@ pub enum DocumentMessage {
},
ImaginateGenerate {
layer_path: Vec<LayerId>,
imaginate_node: Vec<NodeId>,
},
ImaginateRandom {
layer_path: Vec<LayerId>,

View File

@@ -31,7 +31,7 @@ use document_legacy::layers::layer_layer::CachedOutputData;
use document_legacy::layers::style::{RenderData, ViewMode};
use document_legacy::{DocumentError, DocumentResponse, LayerId, Operation as DocumentOperation};
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeInput, NodeNetwork};
use graph_craft::document::{NodeInput, NodeNetwork};
use graphene_core::raster::ImageFrame;
use graphene_core::text::Font;
@@ -466,8 +466,8 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
});
}
ImaginateClear { layer_path } => responses.add(InputFrameRasterizeRegionBelowLayer { layer_path }),
ImaginateGenerate { layer_path, imaginate_node } => {
if let Some(message) = self.rasterize_region_below_layer(document_id, layer_path, preferences, persistent_data, Some(imaginate_node)) {
ImaginateGenerate { layer_path } => {
if let Some(message) = self.rasterize_region_below_layer(document_id, layer_path, preferences, persistent_data) {
responses.add(message);
}
}
@@ -490,13 +490,13 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
// Generate the image
if then_generate {
responses.add(DocumentMessage::ImaginateGenerate { layer_path, imaginate_node });
responses.add(DocumentMessage::ImaginateGenerate { layer_path });
}
}
InputFrameRasterizeRegionBelowLayer { layer_path } => {
if layer_path.is_empty() {
responses.add(NodeGraphMessage::RunDocumentGraph);
} else if let Some(message) = self.rasterize_region_below_layer(document_id, layer_path, preferences, persistent_data, None) {
} else if let Some(message) = self.rasterize_region_below_layer(document_id, layer_path, preferences, persistent_data) {
responses.add(message);
}
}
@@ -967,14 +967,7 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
}
impl DocumentMessageHandler {
pub fn rasterize_region_below_layer(
&mut self,
document_id: u64,
layer_path: Vec<LayerId>,
_preferences: &PreferencesMessageHandler,
persistent_data: &PersistentData,
imaginate_node_path: Option<Vec<NodeId>>,
) -> Option<Message> {
pub fn rasterize_region_below_layer(&mut self, document_id: u64, layer_path: Vec<LayerId>, _preferences: &PreferencesMessageHandler, persistent_data: &PersistentData) -> Option<Message> {
// Prepare the node graph input image
let Some(node_network) = self.document_legacy.layer(&layer_path).ok().and_then(|layer| layer.as_layer_network().ok()) else {
@@ -998,14 +991,7 @@ impl DocumentMessageHandler {
self.restore_document_transform(old_transforms);
// Once JS asynchronously rasterizes the SVG, it will call the `PortfolioMessage::RenderGraphUsingRasterizedRegionBelowLayer` message with the rasterized image data
FrontendMessage::TriggerRasterizeRegionBelowLayer {
document_id,
layer_path,
svg,
size,
imaginate_node_path,
}
.into()
FrontendMessage::TriggerRasterizeRegionBelowLayer { document_id, layer_path, svg, size }.into()
}
// Skip taking a round trip through JS since there's nothing to rasterize, and instead directly call the message which would otherwise be called asynchronously from JS
else {
@@ -1014,7 +1000,6 @@ impl DocumentMessageHandler {
layer_path,
input_image_data: vec![],
size: (0, 0),
imaginate_node_path,
}
.into()
};

View File

@@ -714,7 +714,6 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &NodeGraphExecutor, u64)>
layer_path: Vec::new(),
input_image_data: vec![],
size: (0, 0),
imaginate_node_path: None,
}),
NodeGraphMessage::SelectNodes { nodes } => {
self.selected_nodes = nodes;

View File

@@ -984,7 +984,6 @@ pub fn node_section_font(document_node: &DocumentNode, node_id: NodeId, _context
pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let imaginate_node = [context.nested_path, &[node_id]].concat();
let layer_path = context.layer_path.to_vec();
let resolve_input = |name: &str| {
super::IMAGINATE_NODE
@@ -1140,16 +1139,11 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
TextButton::new("Generate")
.tooltip("Fill layer frame by generating a new image")
.on_update({
let imaginate_node = imaginate_node.clone();
let layer_path = context.layer_path.to_vec();
let controller = controller.clone();
move |_| {
controller.trigger_regenerate();
DocumentMessage::ImaginateGenerate {
layer_path: layer_path.clone(),
imaginate_node: imaginate_node.clone(),
}
.into()
DocumentMessage::ImaginateGenerate { layer_path: layer_path.clone() }.into()
}
})
.widget_holder(),

View File

@@ -100,7 +100,6 @@ pub enum PortfolioMessage {
layer_path: Vec<LayerId>,
input_image_data: Vec<u8>,
size: (u32, u32),
imaginate_node_path: Option<Vec<NodeId>>,
},
SelectDocument {
document_id: u64,

View File

@@ -417,7 +417,6 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
layer_path,
input_image_data,
size,
imaginate_node_path,
} => {
let result = self.executor.submit_node_graph_evaluation(
(document_id, &mut self.documents),