Skip to content

Commit fd81d04

Browse files
TrueDoctorKeavon
andauthored
Fix wrong node parameter widgets, attempt 3 at #2323 (#2334)
* WIP, for TrueDoctor to continue * Expose first implementation type as default type in field metadata * Cleanup --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent e41471c commit fd81d04

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
26972697
.iter()
26982698
.zip(first_node_io.inputs.iter())
26992699
.enumerate()
2700-
.map(|(index, (field, ty))| {
2700+
.map(|(index, (field, node_io_ty))| {
2701+
let ty = field.default_type.as_ref().unwrap_or(node_io_ty);
27012702
let exposed = if index == 0 { *ty != fn_type!(()) } else { field.exposed };
27022703

27032704
match field.value_source {

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::messages::layout::utility_types::widget_prelude::*;
66
use crate::messages::portfolio::document::utility_types::network_interface::InputConnector;
77
use crate::messages::prelude::*;
88

9+
use dyn_any::DynAny;
910
use graph_craft::document::value::TaggedValue;
1011
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
1112
use graph_craft::imaginate_input::{ImaginateMaskStartingFill, ImaginateSamplingMethod};
@@ -2128,24 +2129,30 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
21282129

21292130
let mut number_options = (None, None, None);
21302131
let input_type = match implementation {
2131-
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
2132+
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => 'early_return: {
21322133
if let Some(field) = graphene_core::registry::NODE_METADATA
21332134
.lock()
21342135
.unwrap()
21352136
.get(&proto_node_identifier.name.clone().into_owned())
21362137
.and_then(|metadata| metadata.fields.get(input_index))
21372138
{
21382139
number_options = (field.number_min, field.number_max, field.number_mode_range);
2140+
if let Some(ref default) = field.default_type {
2141+
break 'early_return default.clone();
2142+
}
21392143
}
21402144
let Some(implementations) = &interpreted_executor::node_registry::NODE_REGISTRY.get(proto_node_identifier) else {
21412145
log::error!("Could not get implementation for protonode {proto_node_identifier:?}");
21422146
return Vec::new();
21432147
};
21442148
let proto_node_identifier = proto_node_identifier.clone();
2145-
let input_type = implementations
2149+
let mut input_types = implementations
21462150
.keys()
21472151
.filter_map(|item| item.inputs.get(input_index))
2148-
.find(|item| property_from_type(node_id, input_index, item, number_options, context).is_ok());
2152+
.filter(|ty| property_from_type(node_id, input_index, ty, number_options, context).is_ok())
2153+
.collect::<Vec<_>>();
2154+
input_types.sort_by_key(|ty| ty.type_name());
2155+
let input_type = input_types.first().cloned();
21492156
let Some(input_type) = input_type else {
21502157
log::error!("Could not get input type for protonode {proto_node_identifier:?} at index {input_index:?}");
21512158
return Vec::new();

node-graph/gcore/src/registry.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
use crate::transform::Footprint;
2+
use crate::{NodeIO, NodeIOTypes, Type};
3+
4+
use dyn_any::DynAny;
5+
16
use std::collections::HashMap;
27
use std::ops::Deref;
38
use std::pin::Pin;
49
use std::sync::{LazyLock, Mutex};
510

6-
use dyn_any::DynAny;
7-
8-
use crate::transform::Footprint;
9-
use crate::NodeIO;
10-
use crate::NodeIOTypes;
11-
1211
pub mod types {
1312
/// 0% - 100%
1413
pub type Percentage = f64;
@@ -47,6 +46,7 @@ pub struct FieldMetadata {
4746
pub exposed: bool,
4847
pub widget_override: RegistryWidgetOverride,
4948
pub value_source: RegistryValueSource,
49+
pub default_type: Option<Type>,
5050
pub number_min: Option<f64>,
5151
pub number_max: Option<f64>,
5252
pub number_mode_range: Option<(f64, f64)>,

node-graph/node-macro/src/codegen.rs

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
117117
})
118118
.collect();
119119

120+
let default_types: Vec<_> = fields
121+
.iter()
122+
.map(|field| match field {
123+
ParsedField::Regular { implementations, .. } => match implementations.first() {
124+
Some(ty) => quote!(Some(concrete!(#ty))),
125+
_ => quote!(None),
126+
},
127+
_ => quote!(None),
128+
})
129+
.collect();
130+
120131
let number_min_values: Vec<_> = fields
121132
.iter()
122133
.map(|field| match field {
@@ -292,6 +303,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
292303
description: #input_descriptions,
293304
exposed: #exposed,
294305
value_source: #value_sources,
306+
default_type: #default_types,
295307
number_min: #number_min_values,
296308
number_max: #number_max_values,
297309
number_mode_range: #number_mode_range_values,

0 commit comments

Comments
 (0)