Allow groups to work with the node graph (#1452)

* Initial groups

* Improve graph arangement

* Fix selecting nested layers

* Code review pass

* Change log

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube 2023-11-14 17:17:14 +00:00 committed by GitHub
parent f4ec76f35e
commit 58660f5548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 397 additions and 306 deletions

View file

@ -616,13 +616,23 @@ impl NodeNetwork {
FlowIter {
stack: self.outputs.iter().map(|output| output.node_id).collect(),
network: self,
primary: true,
}
}
pub fn primary_flow_from_opt(&self, id: Option<NodeId>) -> impl Iterator<Item = (&DocumentNode, u64)> {
pub fn primary_flow_from_node(&self, id: Option<NodeId>) -> impl Iterator<Item = (&DocumentNode, u64)> {
FlowIter {
stack: id.map_or_else(|| self.outputs.iter().map(|output| output.node_id).collect(), |id| vec![id]),
network: self,
primary: true,
}
}
pub fn all_dependencies(&self, id: NodeId) -> impl Iterator<Item = (&DocumentNode, u64)> {
FlowIter {
stack: vec![id],
network: self,
primary: false,
}
}
@ -664,6 +674,7 @@ impl NodeNetwork {
struct FlowIter<'a> {
stack: Vec<NodeId>,
network: &'a NodeNetwork,
primary: bool,
}
impl<'a> Iterator for FlowIter<'a> {
type Item = (&'a DocumentNode, NodeId);
@ -671,13 +682,11 @@ impl<'a> Iterator for FlowIter<'a> {
loop {
let node_id = self.stack.pop()?;
if let Some(document_node) = self.network.nodes.get(&node_id) {
self.stack.extend(
document_node
.inputs
.iter()
.take(1) // Only show the primary input
.filter_map(|input| if let NodeInput::Node { node_id: ref_id, .. } = input { Some(*ref_id) } else { None }),
);
let inputs = document_node.inputs.iter().take(if self.primary { 1 } else { usize::MAX });
let node_ids = inputs.filter_map(|input| if let NodeInput::Node { node_id, .. } = input { Some(*node_id) } else { None });
self.stack.extend(node_ids);
return Some((document_node, node_id));
};
}