@@ -3,6 +3,7 @@ use crate::messages::input_mapper::utility_types::macros::action_keys;
3
3
use crate :: messages:: layout:: utility_types:: layout_widget:: { Layout , LayoutGroup , Widget , WidgetCallback , WidgetHolder , WidgetLayout } ;
4
4
use crate :: messages:: layout:: utility_types:: widgets:: button_widgets:: TextButton ;
5
5
use crate :: messages:: prelude:: * ;
6
+ use crate :: node_graph_executor:: NodeGraphExecutor ;
6
7
7
8
use document_legacy:: document:: Document ;
8
9
use document_legacy:: layers:: layer_layer:: LayerLayer ;
@@ -84,6 +85,8 @@ pub struct FrontendNode {
84
85
pub position : ( i32 , i32 ) ,
85
86
pub disabled : bool ,
86
87
pub previewed : bool ,
88
+ #[ serde( rename = "thumbnailSvg" ) ]
89
+ pub thumbnail_svg : Option < String > ,
87
90
}
88
91
89
92
// (link_start, link_end, link_end_input_index)
@@ -254,9 +257,11 @@ impl NodeGraphMessageHandler {
254
257
}
255
258
}
256
259
257
- fn send_graph ( network : & NodeNetwork , responses : & mut VecDeque < Message > ) {
260
+ fn send_graph ( network : & NodeNetwork , executor : & NodeGraphExecutor , layer_path : & Option < Vec < LayerId > > , responses : & mut VecDeque < Message > ) {
258
261
responses. add ( PropertiesPanelMessage :: ResendActiveProperties ) ;
259
262
263
+ let layer_id = layer_path. as_ref ( ) . and_then ( |path| path. last ( ) . copied ( ) ) ;
264
+
260
265
// List of links in format (link_start, link_end, link_end_input_index)
261
266
let links = network
262
267
. nodes
@@ -288,37 +293,49 @@ impl NodeGraphMessageHandler {
288
293
warn ! ( "Node '{}' does not exist in library" , node. name) ;
289
294
continue ;
290
295
} ;
296
+
297
+ let primary_input = node
298
+ . inputs
299
+ . first ( )
300
+ . filter ( |input| input. is_exposed ( ) )
301
+ . and_then ( |_| node_type. inputs . get ( 0 ) )
302
+ . map ( |input_type| input_type. data_type ) ;
303
+ let exposed_inputs = node
304
+ . inputs
305
+ . iter ( )
306
+ . zip ( node_type. inputs . iter ( ) )
307
+ . skip ( 1 )
308
+ . filter ( |( input, _) | input. is_exposed ( ) )
309
+ . map ( |( _, input_type) | NodeGraphInput {
310
+ data_type : input_type. data_type ,
311
+ name : input_type. name . to_string ( ) ,
312
+ } )
313
+ . collect ( ) ;
314
+
315
+ let outputs = node_type
316
+ . outputs
317
+ . iter ( )
318
+ . map ( |output_type| NodeGraphOutput {
319
+ data_type : output_type. data_type ,
320
+ name : output_type. name . to_string ( ) ,
321
+ } )
322
+ . collect ( ) ;
323
+
324
+ let thumbnail_svg = layer_id
325
+ . and_then ( |layer_id| executor. thumbnails . get ( & layer_id) )
326
+ . and_then ( |layer| layer. get ( id) )
327
+ . map ( |svg| svg. to_string ( ) ) ;
328
+
291
329
nodes. push ( FrontendNode {
292
330
id : * id,
293
331
display_name : node. name . clone ( ) ,
294
- primary_input : node
295
- . inputs
296
- . first ( )
297
- . filter ( |input| input. is_exposed ( ) )
298
- . and_then ( |_| node_type. inputs . get ( 0 ) )
299
- . map ( |input_type| input_type. data_type ) ,
300
- exposed_inputs : node
301
- . inputs
302
- . iter ( )
303
- . zip ( node_type. inputs . iter ( ) )
304
- . skip ( 1 )
305
- . filter ( |( input, _) | input. is_exposed ( ) )
306
- . map ( |( _, input_type) | NodeGraphInput {
307
- data_type : input_type. data_type ,
308
- name : input_type. name . to_string ( ) ,
309
- } )
310
- . collect ( ) ,
311
- outputs : node_type
312
- . outputs
313
- . iter ( )
314
- . map ( |output_type| NodeGraphOutput {
315
- data_type : output_type. data_type ,
316
- name : output_type. name . to_string ( ) ,
317
- } )
318
- . collect ( ) ,
332
+ primary_input,
333
+ exposed_inputs,
334
+ outputs,
319
335
position : node. metadata . position . into ( ) ,
320
336
previewed : network. outputs_contain ( * id) ,
321
337
disabled : network. disabled . contains ( id) ,
338
+ thumbnail_svg,
322
339
} )
323
340
}
324
341
responses. add ( FrontendMessage :: UpdateNodeGraph { nodes, links } ) ;
@@ -405,9 +422,9 @@ impl NodeGraphMessageHandler {
405
422
}
406
423
}
407
424
408
- impl MessageHandler < NodeGraphMessage , ( & mut Document , & mut dyn Iterator < Item = & [ LayerId ] > ) > for NodeGraphMessageHandler {
425
+ impl MessageHandler < NodeGraphMessage , ( & mut Document , & NodeGraphExecutor ) > for NodeGraphMessageHandler {
409
426
#[ remain:: check]
410
- fn process_message ( & mut self , message : NodeGraphMessage , responses : & mut VecDeque < Message > , ( document, _selected ) : ( & mut Document , & mut dyn Iterator < Item = & [ LayerId ] > ) ) {
427
+ fn process_message ( & mut self , message : NodeGraphMessage , responses : & mut VecDeque < Message > , ( document, executor ) : ( & mut Document , & NodeGraphExecutor ) ) {
411
428
#[ remain:: sorted]
412
429
match message {
413
430
NodeGraphMessage :: CloseNodeGraph => {
@@ -536,7 +553,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
536
553
}
537
554
}
538
555
if let Some ( network) = self . get_active_network ( document) {
539
- Self :: send_graph ( network, responses) ;
556
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
540
557
}
541
558
self . collect_nested_addresses ( document, responses) ;
542
559
self . update_selected ( document, responses) ;
@@ -561,7 +578,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
561
578
responses. add ( NodeGraphMessage :: InsertNode { node_id, document_node } ) ;
562
579
}
563
580
564
- Self :: send_graph ( network, responses) ;
581
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
565
582
self . update_selected ( document, responses) ;
566
583
}
567
584
}
@@ -571,7 +588,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
571
588
self . nested_path . pop ( ) ;
572
589
}
573
590
if let Some ( network) = self . get_active_network ( document) {
574
- Self :: send_graph ( network, responses) ;
591
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
575
592
}
576
593
self . collect_nested_addresses ( document, responses) ;
577
594
self . update_selected ( document, responses) ;
@@ -622,15 +639,15 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
622
639
node. metadata . position += IVec2 :: new ( displacement_x, displacement_y)
623
640
}
624
641
}
625
- Self :: send_graph ( network, responses) ;
642
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
626
643
}
627
644
NodeGraphMessage :: OpenNodeGraph { layer_path } => {
628
645
self . layer_path = Some ( layer_path) ;
629
646
630
647
if let Some ( network) = self . get_active_network ( document) {
631
648
self . selected_nodes . clear ( ) ;
632
649
633
- Self :: send_graph ( network, responses) ;
650
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
634
651
635
652
let node_types = document_node_types:: collect_node_types ( ) ;
636
653
responses. add ( FrontendMessage :: UpdateNodeTypes { node_types } ) ;
@@ -689,7 +706,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
689
706
}
690
707
NodeGraphMessage :: SendGraph { should_rerender } => {
691
708
if let Some ( network) = self . get_active_network ( document) {
692
- Self :: send_graph ( network, responses) ;
709
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
693
710
if should_rerender {
694
711
if let Some ( layer_path) = self . layer_path . clone ( ) {
695
712
responses. add ( DocumentMessage :: InputFrameRasterizeRegionBelowLayer { layer_path } ) ;
@@ -816,7 +833,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
816
833
. disabled
817
834
. extend ( self . selected_nodes . iter ( ) . filter ( |& id| !network. inputs . contains ( id) && !original_outputs. contains ( id) ) ) ;
818
835
}
819
- Self :: send_graph ( network, responses) ;
836
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
820
837
821
838
// Only generate node graph if one of the selected nodes is connected to the output
822
839
if self . selected_nodes . iter ( ) . any ( |& node_id| network. connected_to_output ( node_id, true ) ) {
@@ -842,7 +859,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
842
859
} else {
843
860
return ;
844
861
}
845
- Self :: send_graph ( network, responses) ;
862
+ Self :: send_graph ( network, executor , & self . layer_path , responses) ;
846
863
}
847
864
self . update_selection_action_buttons ( document, responses) ;
848
865
if let Some ( layer_path) = self . layer_path . clone ( ) {
0 commit comments