Skip to content

Commit 1fc7292

Browse files
committed
WIP: Refactor TypeSource
1 parent 5888f78 commit 1fc7292

File tree

13 files changed

+426
-395
lines changed

13 files changed

+426
-395
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
@@ -871,7 +871,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
871871
};
872872
let Some(output_connector) = output_connector else { return };
873873
self.wire_in_progress_from_connector = network_interface.output_position(&output_connector, selection_network_path);
874-
self.wire_in_progress_type = FrontendGraphDataType::from_type(&network_interface.input_type(clicked_input, breadcrumb_network_path).0);
874+
self.wire_in_progress_type = FrontendGraphDataType::displayed_type(&network_interface.input_type(clicked_input, breadcrumb_network_path));
875875
return;
876876
}
877877

@@ -881,8 +881,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
881881
self.initial_disconnecting = false;
882882

883883
self.wire_in_progress_from_connector = network_interface.output_position(&clicked_output, selection_network_path);
884-
let (output_type, source) = &network_interface.output_type(&clicked_output, breadcrumb_network_path);
885-
self.wire_in_progress_type = FrontendGraphDataType::displayed_type(output_type, source);
884+
let output_type = network_interface.output_type(&clicked_output, breadcrumb_network_path);
885+
self.wire_in_progress_type = FrontendGraphDataType::displayed_type(&output_type);
886886

887887
self.update_node_graph_hints(responses);
888888
return;
@@ -1196,16 +1196,12 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
11961196
return;
11971197
}
11981198
// Get the output types from the network interface
1199-
let (output_type, type_source) = network_interface.output_type(&output_connector.unwrap(), selection_network_path);
12001199
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
12011200
warn!("No network_metadata");
12021201
return;
12031202
};
12041203

1205-
let compatible_type = match type_source {
1206-
TypeSource::RandomProtonodeImplementation | TypeSource::Error(_) => None,
1207-
_ => Some(format!("type:{}", output_type.nested_type())),
1208-
};
1204+
let compatible_type = network_interface.output_type(&output_connector.unwrap(), selection_network_path).add_node_string();
12091205

12101206
let appear_right_of_mouse = if ipp.mouse.position.x > ipp.viewport_bounds.size().x - 173. { -173. } else { 0. };
12111207
let appear_above_mouse = if ipp.mouse.position.y > ipp.viewport_bounds.size().y - 34. { -34. } else { 0. };
@@ -1977,12 +1973,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
19771973
responses.add(NodeGraphMessage::SendGraph);
19781974
}
19791975
NodeGraphMessage::UpdateTypes { resolved_types, node_graph_errors } => {
1980-
for (path, node_type) in resolved_types.add {
1981-
network_interface.resolved_types.types.insert(path.to_vec(), node_type);
1982-
}
1983-
for path in resolved_types.remove {
1984-
network_interface.resolved_types.types.remove(&path.to_vec());
1985-
}
1976+
network_interface.resolved_types.update(resolved_types);
19861977
self.node_graph_errors = node_graph_errors;
19871978
}
19881979
NodeGraphMessage::UpdateActionButtons => {
@@ -2096,16 +2087,7 @@ impl NodeGraphMessageHandler {
20962087
.popover_layout({
20972088
// Showing only compatible types
20982089
let compatible_type = match (selection_includes_layers, has_multiple_selection, selected_layer) {
2099-
(true, false, Some(layer)) => {
2100-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network_interface);
2101-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2102-
if let Some(node_id) = node_type {
2103-
let (output_type, _) = network_interface.output_type(&OutputConnector::node(node_id, 0), &[]);
2104-
Some(format!("type:{}", output_type.nested_type()))
2105-
} else {
2106-
None
2107-
}
2108-
}
2090+
(true, false, Some(layer)) => network_interface.output_type(&OutputConnector::node(node_id, 0), &[]).add_node_string(),
21092091
_ => None,
21102092
};
21112093

@@ -2418,17 +2400,10 @@ impl NodeGraphMessageHandler {
24182400
.icon(Some("Node".to_string()))
24192401
.tooltip("Add an operation to the end of this layer's chain of nodes")
24202402
.popover_layout({
2421-
let layer_identifier = LayerNodeIdentifier::new(layer, context.network_interface);
2422-
let compatible_type = {
2423-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer_identifier, context.network_interface);
2424-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2425-
if let Some(node_id) = node_type {
2426-
let (output_type, _) = context.network_interface.output_type(&OutputConnector::node(node_id, 0), &[]);
2427-
Some(format!("type:{}", output_type.nested_type()))
2428-
} else {
2429-
None
2430-
}
2431-
};
2403+
let compatible_type = context
2404+
.network_interface
2405+
.upstream_output_connector(&InputConnector::node(layer, 1), &[])
2406+
.and_then(|upstream_output| context.network_interface.output_type(&upstream_output, &[]).add_node_string());
24322407

24332408
let mut node_chooser = NodeCatalog::new();
24342409
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)