Skip to content

Commit e41471c

Browse files
committed
Fix wrong node parameter widgets, attempt 2 at #2323
1 parent 8d0c5d3 commit e41471c

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

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

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,24 @@ pub fn start_widgets(document_node: &DocumentNode, node_id: NodeId, index: usize
8989
widgets
9090
}
9191

92-
pub(crate) fn property_from_type(node_id: NodeId, index: usize, ty: &Type, number_options: (Option<f64>, Option<f64>, Option<(f64, f64)>), context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
92+
pub(crate) fn property_from_type(
93+
node_id: NodeId,
94+
index: usize,
95+
ty: &Type,
96+
number_options: (Option<f64>, Option<f64>, Option<(f64, f64)>),
97+
context: &mut NodePropertiesContext,
98+
) -> Result<Vec<LayoutGroup>, Vec<LayoutGroup>> {
9399
let Some(name) = context.network_interface.input_name(&node_id, index, context.selection_network_path) else {
94100
log::warn!("A widget failed to be built for node {node_id}, index {index} because the input name could not be determined");
95-
return vec![];
101+
return Err(vec![]);
96102
};
97-
98103
let Some(network) = context.network_interface.network(context.selection_network_path) else {
99104
log::warn!("A widget failed to be built for node {node_id}, index {index} because the network could not be determined");
100-
return vec![];
105+
return Err(vec![]);
101106
};
102-
103107
let Some(document_node) = network.nodes.get(&node_id) else {
104108
log::warn!("A widget failed to be built for node {node_id}, index {index} because the document node does not exist");
105-
return vec![];
109+
return Err(vec![]);
106110
};
107111

108112
let (mut number_min, mut number_max, range) = number_options;
@@ -247,7 +251,7 @@ pub(crate) fn property_from_type(node_id: NodeId, index: usize, ty: &Type, numbe
247251
))
248252
.widget_holder(),
249253
]);
250-
widgets.into()
254+
return Err(vec![widgets.into()]);
251255
}
252256
}
253257
}
@@ -257,8 +261,10 @@ pub(crate) fn property_from_type(node_id: NodeId, index: usize, ty: &Type, numbe
257261
Type::Fn(_, out) => return property_from_type(node_id, index, out, number_options, context),
258262
Type::Future(_) => vec![TextLabel::new("Future type (not supported)").widget_holder()].into(),
259263
};
264+
260265
extra_widgets.push(widgets);
261-
extra_widgets
266+
267+
Ok(extra_widgets)
262268
}
263269

264270
pub fn text_widget(document_node: &DocumentNode, node_id: NodeId, index: usize, name: &str, blank_assist: bool) -> Vec<WidgetHolder> {
@@ -2121,18 +2127,35 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
21212127
};
21222128

21232129
let mut number_options = (None, None, None);
2124-
if let DocumentNodeImplementation::ProtoNode(proto_node_identifier) = implementation {
2125-
if let Some(field) = graphene_core::registry::NODE_METADATA
2126-
.lock()
2127-
.unwrap()
2128-
.get(&proto_node_identifier.name.clone().into_owned())
2129-
.and_then(|metadata| metadata.fields.get(input_index))
2130-
{
2131-
number_options = (field.number_min, field.number_max, field.number_mode_range);
2130+
let input_type = match implementation {
2131+
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
2132+
if let Some(field) = graphene_core::registry::NODE_METADATA
2133+
.lock()
2134+
.unwrap()
2135+
.get(&proto_node_identifier.name.clone().into_owned())
2136+
.and_then(|metadata| metadata.fields.get(input_index))
2137+
{
2138+
number_options = (field.number_min, field.number_max, field.number_mode_range);
2139+
}
2140+
let Some(implementations) = &interpreted_executor::node_registry::NODE_REGISTRY.get(proto_node_identifier) else {
2141+
log::error!("Could not get implementation for protonode {proto_node_identifier:?}");
2142+
return Vec::new();
2143+
};
2144+
let proto_node_identifier = proto_node_identifier.clone();
2145+
let input_type = implementations
2146+
.keys()
2147+
.filter_map(|item| item.inputs.get(input_index))
2148+
.find(|item| property_from_type(node_id, input_index, item, number_options, context).is_ok());
2149+
let Some(input_type) = input_type else {
2150+
log::error!("Could not get input type for protonode {proto_node_identifier:?} at index {input_index:?}");
2151+
return Vec::new();
2152+
};
2153+
input_type.clone()
21322154
}
2133-
}
2134-
let input_type = context.network_interface.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path).0;
2135-
property_from_type(node_id, input_index, &input_type, number_options, context)
2155+
_ => context.network_interface.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path).0,
2156+
};
2157+
2158+
property_from_type(node_id, input_index, &input_type, number_options, context).unwrap_or_else(|value| value)
21362159
});
21372160
layout.extend(row);
21382161
}

0 commit comments

Comments
 (0)