@@ -38,6 +38,30 @@ pub struct NodePropertiesContext<'a> {
3838 pub document_name : & ' a str ,
3939}
4040
41+ impl NodePropertiesContext < ' _ > {
42+ pub fn call_widget_override ( & mut self , node_id : & NodeId , index : usize ) -> Option < Vec < LayoutGroup > > {
43+ //let current_override = //Get mutable reference from transient metadata
44+ //let mut widget_override = std::mem::replace(&mut WidgetOverrideLambda(Box::new()), current_override);
45+ // let layout = widget_override.0(node_id, context);
46+ //let current_override = //Get mutable reference from transient metadata (now empty)
47+ //let empty_widget_override = std::mem::replace(&mut widget_override, current_override) // Put back the taken override
48+ // Some(layout)
49+ let Some ( input_properties_row) = self . network_interface . input_properties_row ( node_id, index, self . selection_network_path ) else {
50+ log:: error!( "Could not get input properties row in call_widget_override" ) ;
51+ return None ;
52+ } ;
53+ let Some ( widget_override_lambda) = input_properties_row. widget_override . as_ref ( ) . and_then ( |widget_override| INPUT_OVERRIDES . get ( widget_override) ) else {
54+ log:: error!( "Could not get widget override lambda in call_widget_override" ) ;
55+ return None ;
56+ } ;
57+ widget_override_lambda ( * node_id, index, self )
58+ . map_err ( |error| {
59+ log:: error!( "Error in widget override lambda: {}" , error) ;
60+ } )
61+ . ok ( )
62+ }
63+ }
64+
4165/// Acts as a description for a [DocumentNode] before it gets instantiated as one.
4266#[ derive( Clone ) ]
4367pub struct DocumentNodeDefinition {
@@ -89,7 +113,10 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
89113 ..Default :: default ( )
90114 } ,
91115 persistent_node_metadata: DocumentNodePersistentMetadata {
92- input_properties: vec![ PropertiesRow :: with_override( "In" , WidgetOverride :: string( "The identity node simply passes its data through." ) ) ] ,
116+ input_properties: vec![ PropertiesRow :: with_override(
117+ "In" ,
118+ WidgetOverride :: String ( "The identity node simply passes its data through." . to_string( ) ) ,
119+ ) ] ,
93120 output_names: vec![ "Out" . to_string( ) ] ,
94121 ..Default :: default ( )
95122 } ,
@@ -112,7 +139,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
112139 persistent_node_metadata: DocumentNodePersistentMetadata {
113140 input_properties: vec![ PropertiesRow :: with_override(
114141 "In" ,
115- WidgetOverride :: string ( "The Monitor node is used by the editor to access the data flowing through it." ) ,
142+ WidgetOverride :: String ( "The Monitor node is used by the editor to access the data flowing through it." . to_string ( ) ) ,
116143 ) ] ,
117144 output_names: vec![ "Out" . to_string( ) ] ,
118145 ..Default :: default ( )
@@ -285,7 +312,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
285312 ..Default :: default ( )
286313 } ,
287314 persistent_node_metadata: DocumentNodePersistentMetadata {
288- input_properties: vec![ "Artboards" . into( ) , "Contents" . into( ) , "Location" . into( ) , "Dimensions" . into( ) , "Background" . into( ) , "Clip" . into( ) ] ,
315+ input_properties: vec![
316+ PropertiesRow :: with_override( "Artboards" , WidgetOverride :: Hidden ) ,
317+ PropertiesRow :: with_override( "Contents" , WidgetOverride :: Hidden ) ,
318+ "Location" . into( ) ,
319+ "Dimensions" . into( ) ,
320+ "Background" . into( ) ,
321+ "Clip" . into( ) ,
322+ ] ,
289323 output_names: vec![ "Out" . to_string( ) ] ,
290324 node_type_metadata: NodeTypePersistentMetadata :: layer( IVec2 :: new( 0 , 0 ) ) ,
291325 network_metadata: Some ( NodeNetworkMetadata {
@@ -366,7 +400,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
366400 ..Default :: default ( )
367401 } ,
368402 persistent_node_metadata: DocumentNodePersistentMetadata {
369- input_properties: vec![ "api" . into ( ) , "path" . into( ) ] ,
403+ input_properties: vec![ PropertiesRow :: with_override ( "api" , WidgetOverride :: Hidden ) , "path" . into( ) ] ,
370404 output_names: vec![ "Image Frame" . to_string( ) ] ,
371405 network_metadata: Some ( NodeNetworkMetadata {
372406 persistent_metadata: NodeNetworkPersistentMetadata {
@@ -689,7 +723,10 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
689723 ..Default :: default ( )
690724 } ,
691725 persistent_node_metadata: DocumentNodePersistentMetadata {
692- input_properties: vec![ PropertiesRow :: with_override( "Image" , WidgetOverride :: string( "Creates an embedded image with the given transform." ) ) ] ,
726+ input_properties: vec![ PropertiesRow :: with_override(
727+ "Image" ,
728+ WidgetOverride :: String ( "Creates an embedded image with the given transform." . to_string( ) ) ,
729+ ) ] ,
693730 output_names: vec![ "Image" . to_string( ) ] ,
694731 network_metadata: Some ( NodeNetworkMetadata {
695732 persistent_metadata: NodeNetworkPersistentMetadata {
@@ -754,7 +791,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
754791 input_properties: vec![
755792 "Clip" . into( ) ,
756793 "Seed" . into( ) ,
757- "Scale" . into ( ) ,
794+ PropertiesRow :: with_override ( "Scale" , WidgetOverride :: Custom ( "noise_properties_scale" . to_string ( ) ) ) ,
758795 "Noise Type" . into( ) ,
759796 "Domain Warp Type" . into( ) ,
760797 "Domain Warp Amplitude" . into( ) ,
@@ -817,7 +854,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
817854 ..Default :: default ( )
818855 } ,
819856 persistent_node_metadata: DocumentNodePersistentMetadata {
820- input_properties: vec![ "Image" . into ( ) , "Stencil" . into( ) ] ,
857+ input_properties: vec![ PropertiesRow :: with_override ( "Image" , WidgetOverride :: Hidden ) , "Stencil" . into( ) ] ,
821858 output_names: vec![ "Image" . to_string( ) ] ,
822859 ..Default :: default ( )
823860 } ,
@@ -840,7 +877,11 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
840877 ..Default :: default ( )
841878 } ,
842879 persistent_node_metadata: DocumentNodePersistentMetadata {
843- input_properties: vec![ "Image" . into( ) , "Insertion" . into( ) , "Replace" . into( ) ] ,
880+ input_properties: vec![
881+ PropertiesRow :: with_override( "Image" , WidgetOverride :: Hidden ) ,
882+ PropertiesRow :: with_override( "Insertion" , WidgetOverride :: Hidden ) ,
883+ "Replace" . into( ) ,
884+ ] ,
844885 output_names: vec![ "Image" . to_string( ) ] ,
845886 ..Default :: default ( )
846887 } ,
@@ -1111,7 +1152,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
11111152 ..Default :: default ( )
11121153 } ,
11131154 persistent_node_metadata: DocumentNodePersistentMetadata {
1114- input_properties: vec![ PropertiesRow :: with_override( "Image" , WidgetOverride :: string ( "A bitmap image is embedded in this node" ) ) ] ,
1155+ input_properties: vec![ PropertiesRow :: with_override( "Image" , WidgetOverride :: String ( "A bitmap image is embedded in this node" . to_string ( ) ) ) ] ,
11151156 output_names: vec![ "Image" . to_string( ) ] ,
11161157 network_metadata: Some ( NodeNetworkMetadata {
11171158 persistent_metadata: NodeNetworkPersistentMetadata {
@@ -2673,6 +2714,47 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
26732714 description : Cow :: Borrowed ( "TODO" ) ,
26742715} ) ;
26752716
2717+ static INPUT_OVERRIDES : once_cell:: sync:: Lazy < HashMap < String , Box < dyn Fn ( NodeId , usize , & mut NodePropertiesContext ) -> Result < Vec < LayoutGroup > , String > + Send + Sync > > > =
2718+ once_cell:: sync:: Lazy :: new ( static_input_properties) ;
2719+
2720+ /// Defines the logic for inputs to display a custom properties panel widget.
2721+ fn static_input_properties ( ) -> HashMap < String , Box < dyn Fn ( NodeId , usize , & mut NodePropertiesContext ) -> Result < Vec < LayoutGroup > , String > + Send + Sync > > {
2722+ let mut map: HashMap < String , Box < dyn Fn ( NodeId , usize , & mut NodePropertiesContext ) -> Result < Vec < LayoutGroup > , String > + Send + Sync > > = HashMap :: new ( ) ;
2723+ map. insert ( "hidden" . to_string ( ) , Box :: new ( |_node_id, _index, _context| Ok ( Vec :: new ( ) ) ) ) ;
2724+ map. insert (
2725+ "string" . to_string ( ) ,
2726+ Box :: new ( |node_id, index, context| {
2727+ let Some ( value) = context. network_interface . input_metadata ( & node_id, index, "string_properties" , context. selection_network_path ) else {
2728+ return Err ( format ! ( "Could not get string properties for node {}" , node_id) ) ;
2729+ } ;
2730+ let Some ( string) = value. as_str ( ) else {
2731+ return Err ( format ! ( "Could not downcast string properties for node {}" , node_id) ) ;
2732+ } ;
2733+ Ok ( node_properties:: string_properties ( string. to_string ( ) ) )
2734+ } ) ,
2735+ ) ;
2736+ map. insert (
2737+ "noise_properties_scale" . to_string ( ) ,
2738+ Box :: new ( |node_id, index, context| {
2739+ let network = context. network_interface . network ( context. selection_network_path ) . ok_or ( "network not found in noise_properties_scale" ) ?;
2740+ let document_node = network. nodes . get ( & node_id) . ok_or ( "node not found in noise_properties_scale" ) ?;
2741+ let current_noise_type = document_node. inputs . iter ( ) . find_map ( |input| match input. as_value ( ) {
2742+ Some ( & TaggedValue :: NoiseType ( noise_type) ) => Some ( noise_type) ,
2743+ _ => None ,
2744+ } ) ;
2745+ let coherent_noise_active = current_noise_type != Some ( NoiseType :: WhiteNoise ) ;
2746+ let input_name = context
2747+ . network_interface
2748+ . input_name ( & node_id, index, context. selection_network_path )
2749+ . ok_or ( "input name not found in noise_properties_scale" ) ?;
2750+
2751+ let scale = node_properties:: number_widget ( document_node, node_id, 2 , input_name, NumberInput :: default ( ) . min ( 0. ) . disabled ( !coherent_noise_active) , true ) ;
2752+ Ok ( vec ! [ scale. into( ) ] )
2753+ } ) ,
2754+ ) ;
2755+ map
2756+ }
2757+
26762758pub fn resolve_document_node_type ( identifier : & str ) -> Option < & DocumentNodeDefinition > {
26772759 DOCUMENT_NODE_TYPES . iter ( ) . find ( |definition| definition. identifier == identifier)
26782760}
0 commit comments