Skip to content

Commit 78d17b1

Browse files
committed
Dynamic type based properties for protonode inputs
1 parent 459a244 commit 78d17b1

File tree

1 file changed

+22
-40
lines changed

1 file changed

+22
-40
lines changed

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

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,51 +1572,33 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
15721572
let number_of_inputs = context.network_interface.number_of_inputs(&node_id, context.selection_network_path);
15731573
for input_index in 1..number_of_inputs {
15741574
let row = context.call_widget_override(&node_id, input_index).unwrap_or_else(|| {
1575-
let Some(implementation) = context.network_interface.implementation(&node_id, context.selection_network_path) else {
1576-
log::error!("Could not get implementation for node {node_id}");
1577-
return Vec::new();
1578-
};
1579-
15801575
let mut number_options = (None, None, None);
15811576
let mut display_decimal_places = None;
15821577
let mut step = None;
15831578
let mut unit_suffix = None;
1584-
let input_type = match implementation {
1585-
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => 'early_return: {
1586-
if let Some(field) = graphene_std::registry::NODE_METADATA
1587-
.lock()
1588-
.unwrap()
1589-
.get(proto_node_identifier)
1590-
.and_then(|metadata| metadata.fields.get(input_index))
1591-
{
1592-
number_options = (field.number_min, field.number_max, field.number_mode_range);
1593-
display_decimal_places = field.number_display_decimal_places;
1594-
unit_suffix = field.unit;
1595-
step = field.number_step;
1596-
if let Some(ref default) = field.default_type {
1597-
break 'early_return default.clone();
1598-
}
1599-
}
1600-
1601-
let Some(implementations) = &interpreted_executor::node_registry::NODE_REGISTRY.get(proto_node_identifier) else {
1602-
log::error!("Could not get implementation for protonode {proto_node_identifier:?}");
1603-
return Vec::new();
1604-
};
1605-
1606-
let mut input_types = implementations.keys().filter_map(|item| item.inputs.get(input_index)).collect::<Vec<_>>();
1607-
input_types.sort_by_key(|ty| ty.type_name());
1608-
let input_type = input_types.first().cloned();
1609-
1610-
let Some(input_type) = input_type else { return Vec::new() };
1611-
input_type.clone()
1612-
}
1613-
_ => context
1614-
.network_interface
1615-
.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path)
1616-
.compiled_nested_type()
1617-
.cloned()
1618-
.unwrap_or(concrete!(())),
1579+
let input_type = context
1580+
.network_interface
1581+
.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path)
1582+
.compiled_nested_type()
1583+
.cloned()
1584+
.unwrap_or(concrete!(()));
1585+
let Some(implementation) = context.network_interface.implementation(&node_id, context.selection_network_path) else {
1586+
log::error!("Could not get implementation for node {node_id}");
1587+
return Vec::new();
16191588
};
1589+
if let DocumentNodeImplementation::ProtoNode(proto_node_identifier) = implementation {
1590+
if let Some(field) = graphene_std::registry::NODE_METADATA
1591+
.lock()
1592+
.unwrap()
1593+
.get(proto_node_identifier)
1594+
.and_then(|metadata| metadata.fields.get(input_index))
1595+
{
1596+
number_options = (field.number_min, field.number_max, field.number_mode_range);
1597+
display_decimal_places = field.number_display_decimal_places;
1598+
unit_suffix = field.unit;
1599+
step = field.number_step;
1600+
}
1601+
}
16201602

16211603
property_from_type(node_id, input_index, &input_type, number_options, unit_suffix, display_decimal_places, step, context).unwrap_or_else(|value| value)
16221604
});

0 commit comments

Comments
 (0)