Skip to content

Commit 6c96ba8

Browse files
committed
WIP: Refactor TypeSource
1 parent 0a15315 commit 6c96ba8

File tree

13 files changed

+429
-390
lines changed

13 files changed

+429
-390
lines changed

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,14 +2787,9 @@ impl DocumentMessageHandler {
27872787
.popover_layout({
27882788
// Showing only compatible types
27892789
let compatible_type = selected_layer.and_then(|layer| {
2790-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, &self.network_interface);
2791-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2792-
if let Some(node_id) = node_type {
2793-
let (output_type, _) = self.network_interface.output_type(&OutputConnector::node(node_id, 0), &self.selection_network_path);
2794-
Some(format!("type:{}", output_type.nested_type()))
2795-
} else {
2796-
None
2797-
}
2790+
self.network_interface
2791+
.upstream_output_connector(&InputConnector::node(layer.to_node(), 1), &[])
2792+
.and_then(|upstream_output| self.network_interface.output_type(&upstream_output, &[]).add_node_string())
27982793
});
27992794

28002795
let mut node_chooser = NodeCatalog::new();

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ impl<'a> ModifyInputsContext<'a> {
303303
// If inserting a 'Path' node, insert a 'Flatten Path' node if the type is `Graphic`.
304304
// TODO: Allow the 'Path' node to operate on table data by utilizing the reference (index or ID?) for each row.
305305
if node_definition.identifier == "Path" {
306-
let layer_input_type = self.network_interface.input_type(&InputConnector::node(output_layer.to_node(), 1), &[]).0.nested_type().clone();
307-
if layer_input_type == concrete!(Table<Graphic>) {
306+
let layer_input_type = self.network_interface.input_type(&InputConnector::node(output_layer.to_node(), 1), &[]).into_compiled_nested_type();
307+
if layer_input_type == Some(concrete!(Table<Graphic>)) {
308308
let Some(flatten_path_definition) = resolve_document_node_type("Flatten Path") else {
309309
log::error!("Flatten Path does not exist in ModifyInputsContext::existing_node_id");
310310
return None;

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

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
878878
};
879879
let Some(output_connector) = output_connector else { return };
880880
self.wire_in_progress_from_connector = network_interface.output_position(&output_connector, selection_network_path);
881-
self.wire_in_progress_type = FrontendGraphDataType::from_type(&network_interface.input_type(clicked_input, breadcrumb_network_path).0);
881+
self.wire_in_progress_type = FrontendGraphDataType::displayed_type(&network_interface.input_type(clicked_input, breadcrumb_network_path));
882882
return;
883883
}
884884

@@ -888,8 +888,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
888888
self.initial_disconnecting = false;
889889

890890
self.wire_in_progress_from_connector = network_interface.output_position(&clicked_output, selection_network_path);
891-
let (output_type, source) = &network_interface.output_type(&clicked_output, breadcrumb_network_path);
892-
self.wire_in_progress_type = FrontendGraphDataType::displayed_type(output_type, source);
891+
let output_type = network_interface.output_type(&clicked_output, breadcrumb_network_path);
892+
self.wire_in_progress_type = FrontendGraphDataType::displayed_type(&output_type);
893893

894894
self.update_node_graph_hints(responses);
895895
return;
@@ -1207,16 +1207,12 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
12071207
}
12081208

12091209
// Get the output types from the network interface
1210-
let (output_type, type_source) = network_interface.output_type(&output_connector, selection_network_path);
12111210
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
12121211
warn!("No network_metadata");
12131212
return;
12141213
};
12151214

1216-
let compatible_type = match type_source {
1217-
TypeSource::RandomProtonodeImplementation | TypeSource::Error(_) => None,
1218-
_ => Some(format!("type:{}", output_type.nested_type())),
1219-
};
1215+
let compatible_type = network_interface.output_type(&output_connector.unwrap(), selection_network_path).add_node_string();
12201216

12211217
let appear_right_of_mouse = if ipp.mouse.position.x > ipp.viewport_bounds.size().x - 173. { -173. } else { 0. };
12221218
let appear_above_mouse = if ipp.mouse.position.y > ipp.viewport_bounds.size().y - 34. { -34. } else { 0. };
@@ -1990,12 +1986,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
19901986
responses.add(NodeGraphMessage::SendGraph);
19911987
}
19921988
NodeGraphMessage::UpdateTypes { resolved_types, node_graph_errors } => {
1993-
for (path, node_type) in resolved_types.add {
1994-
network_interface.resolved_types.types.insert(path.to_vec(), node_type);
1995-
}
1996-
for path in resolved_types.remove {
1997-
network_interface.resolved_types.types.remove(&path.to_vec());
1998-
}
1989+
network_interface.resolved_types.update(resolved_types);
19991990
self.node_graph_errors = node_graph_errors;
20001991
}
20011992
NodeGraphMessage::UpdateActionButtons => {
@@ -2109,16 +2100,7 @@ impl NodeGraphMessageHandler {
21092100
.popover_layout({
21102101
// Showing only compatible types
21112102
let compatible_type = match (selection_includes_layers, has_multiple_selection, selected_layer) {
2112-
(true, false, Some(layer)) => {
2113-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network_interface);
2114-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2115-
if let Some(node_id) = node_type {
2116-
let (output_type, _) = network_interface.output_type(&OutputConnector::node(node_id, 0), &[]);
2117-
Some(format!("type:{}", output_type.nested_type()))
2118-
} else {
2119-
None
2120-
}
2121-
}
2103+
(true, false, Some(layer)) => network_interface.output_type(&OutputConnector::node(node_id, 0), &[]).add_node_string(),
21222104
_ => None,
21232105
};
21242106

@@ -2431,17 +2413,10 @@ impl NodeGraphMessageHandler {
24312413
.icon(Some("Node".to_string()))
24322414
.tooltip("Add an operation to the end of this layer's chain of nodes")
24332415
.popover_layout({
2434-
let layer_identifier = LayerNodeIdentifier::new(layer, context.network_interface);
2435-
let compatible_type = {
2436-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer_identifier, context.network_interface);
2437-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2438-
if let Some(node_id) = node_type {
2439-
let (output_type, _) = context.network_interface.output_type(&OutputConnector::node(node_id, 0), &[]);
2440-
Some(format!("type:{}", output_type.nested_type()))
2441-
} else {
2442-
None
2443-
}
2444-
};
2416+
let compatible_type = context
2417+
.network_interface
2418+
.upstream_output_connector(&InputConnector::node(layer, 1), &[])
2419+
.and_then(|upstream_output| context.network_interface.output_type(&upstream_output, &[]).add_node_string());
24452420

24462421
let mut node_chooser = NodeCatalog::new();
24472422
node_chooser.intial_search = compatible_type.unwrap_or("".to_string());

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,11 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
15501550

15511551
input_type.clone()
15521552
}
1553-
_ => context.network_interface.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path).0,
1553+
_ => context
1554+
.network_interface
1555+
.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path)
1556+
.into_compiled_nested_type()
1557+
.unwrap_or(concrete!(())),
15541558
};
15551559

15561560
property_from_type(node_id, input_index, &input_type, number_options, unit_suffix, display_decimal_places, step, context).unwrap_or_else(|value| value)
@@ -1932,7 +1936,7 @@ pub struct ParameterWidgetsInfo<'a> {
19321936
impl<'a> ParameterWidgetsInfo<'a> {
19331937
pub fn new(node_id: NodeId, index: usize, blank_assist: bool, context: &'a mut NodePropertiesContext) -> ParameterWidgetsInfo<'a> {
19341938
let (name, description) = context.network_interface.displayed_input_name_and_description(&node_id, index, context.selection_network_path);
1935-
let input_type = FrontendGraphDataType::from_type(&context.network_interface.input_type(&InputConnector::node(node_id, index), context.selection_network_path).0);
1939+
let input_type = FrontendGraphDataType::from_type(&context.network_interface.input_type(&InputConnector::node(node_id, index), context.selection_network_path));
19361940
let document_node = context.network_interface.document_node(&node_id, context.selection_network_path);
19371941

19381942
ParameterWidgetsInfo {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ impl FrontendGraphDataType {
4242
}
4343
}
4444

45-
pub fn displayed_type(input: &Type, type_source: &TypeSource) -> Self {
46-
match type_source {
47-
TypeSource::Error(_) | TypeSource::RandomProtonodeImplementation => Self::General,
48-
_ => Self::from_type(input),
45+
pub fn displayed_type(type_source: TypeSource) -> Self {
46+
match type_source.compiled_nested_type() {
47+
Some(nested_type) => Self::from_type(&nested_type),
48+
None => Self::General,
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)