Skip to content

Commit 7ee0d9a

Browse files
4adexKeavon
andauthored
Make the node chooser auto filter by layer input type when applicable (#2841)
* Fix showing only compatible nodes * Implement search on Add Node button * Fix add node behaviour * Improve type identification logic * Fix input type identification --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent f299497 commit 7ee0d9a

File tree

3 files changed

+80
-16
lines changed

3 files changed

+80
-16
lines changed

editor/src/messages/layout/utility_types/widgets/input_widgets.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ pub enum NumberInputMode {
332332
pub struct NodeCatalog {
333333
pub disabled: bool,
334334

335+
#[serde(rename = "initialSearchTerm")]
336+
pub intial_search: String,
337+
335338
// Callbacks
336339
#[serde(skip)]
337340
#[derivative(Debug = "ignore", PartialEq = "ignore")]

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,22 @@ impl DocumentMessageHandler {
27092709
.tooltip("Add an operation to the end of this layer's chain of nodes")
27102710
.disabled(!has_selection || has_multiple_selection)
27112711
.popover_layout({
2712-
let node_chooser = NodeCatalog::new()
2712+
// Showing only compatible types
2713+
let compatible_type = selected_layer.and_then(|layer| {
2714+
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, &self.network_interface);
2715+
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2716+
if let Some(node_id) = node_type {
2717+
let (output_type, _) = self.network_interface.output_type(&node_id, 0, &self.selection_network_path);
2718+
Some(format!("type:{}", output_type.nested_type()))
2719+
} else {
2720+
None
2721+
}
2722+
});
2723+
2724+
let mut node_chooser = NodeCatalog::new();
2725+
node_chooser.intial_search = compatible_type.unwrap_or("".to_string());
2726+
2727+
let node_chooser = node_chooser
27132728
.on_update(move |node_type| {
27142729
if let Some(layer) = selected_layer {
27152730
NodeGraphMessage::CreateNodeInLayerWithTransaction {

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

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,26 +2017,57 @@ impl NodeGraphMessageHandler {
20172017
let selection_all_locked = network_interface.selected_nodes().selected_unlocked_layers(network_interface).count() == 0;
20182018
let selection_all_visible = selected_nodes.selected_nodes().all(|node_id| network_interface.is_visible(node_id, breadcrumb_network_path));
20192019

2020+
let mut selected_layers = selected_nodes.selected_layers(network_interface.document_metadata());
2021+
let selected_layer = selected_layers.next();
2022+
let has_multiple_selection = selected_layers.next().is_some();
2023+
20202024
let mut widgets = vec![
20212025
PopoverButton::new()
20222026
.icon(Some("Node".to_string()))
20232027
.tooltip("New Node (Right Click)")
20242028
.popover_layout({
2025-
let node_chooser = NodeCatalog::new()
2029+
// Showing only compatible types
2030+
let compatible_type = match (selection_includes_layers, has_multiple_selection, selected_layer) {
2031+
(true, false, Some(layer)) => {
2032+
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network_interface);
2033+
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2034+
if let Some(node_id) = node_type {
2035+
let (output_type, _) = network_interface.output_type(&node_id, 0, &[]);
2036+
Some(format!("type:{}", output_type.nested_type()))
2037+
} else {
2038+
None
2039+
}
2040+
}
2041+
_ => None,
2042+
};
2043+
2044+
let single_layer_selected = selection_includes_layers && !has_multiple_selection;
2045+
2046+
let mut node_chooser = NodeCatalog::new();
2047+
node_chooser.intial_search = compatible_type.unwrap_or("".to_string());
2048+
2049+
let node_chooser = node_chooser
20262050
.on_update(move |node_type| {
2027-
let node_id = NodeId::new();
2028-
2029-
Message::Batched {
2030-
messages: Box::new([
2031-
NodeGraphMessage::CreateNodeFromContextMenu {
2032-
node_id: Some(node_id),
2033-
node_type: node_type.clone(),
2034-
xy: None,
2035-
add_transaction: true,
2036-
}
2037-
.into(),
2038-
NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into(),
2039-
]),
2051+
if let (true, Some(layer)) = (single_layer_selected, selected_layer) {
2052+
NodeGraphMessage::CreateNodeInLayerWithTransaction {
2053+
node_type: node_type.clone(),
2054+
layer: LayerNodeIdentifier::new_unchecked(layer.to_node()),
2055+
}
2056+
.into()
2057+
} else {
2058+
let node_id = NodeId::new();
2059+
Message::Batched {
2060+
messages: Box::new([
2061+
NodeGraphMessage::CreateNodeFromContextMenu {
2062+
node_id: Some(node_id),
2063+
node_type: node_type.clone(),
2064+
xy: None,
2065+
add_transaction: true,
2066+
}
2067+
.into(),
2068+
NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into(),
2069+
]),
2070+
}
20402071
}
20412072
})
20422073
.widget_holder();
@@ -2308,7 +2339,22 @@ impl NodeGraphMessageHandler {
23082339
.icon(Some("Node".to_string()))
23092340
.tooltip("Add an operation to the end of this layer's chain of nodes")
23102341
.popover_layout({
2311-
let node_chooser = NodeCatalog::new()
2342+
let layer_identifier = LayerNodeIdentifier::new(layer, &context.network_interface);
2343+
let compatible_type = {
2344+
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer_identifier, &context.network_interface);
2345+
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2346+
if let Some(node_id) = node_type {
2347+
let (output_type, _) = context.network_interface.output_type(&node_id, 0, &[]);
2348+
Some(format!("type:{}", output_type.nested_type()))
2349+
} else {
2350+
None
2351+
}
2352+
};
2353+
2354+
let mut node_chooser = NodeCatalog::new();
2355+
node_chooser.intial_search = compatible_type.unwrap_or("".to_string());
2356+
2357+
let node_chooser = node_chooser
23122358
.on_update(move |node_type| {
23132359
NodeGraphMessage::CreateNodeInLayerWithTransaction {
23142360
node_type: node_type.clone(),

0 commit comments

Comments
 (0)