Thumbnails for the layer node (#1210)

* Thumbnails for the layer node

* Raster node graph frames

* Downscale to a random resolution

* Cleanup and bug fixes

* Generate paths before duplicating outputs

* Fix stable id test

* Code review changes

* Code review pass with minor changes

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube 2023-05-18 05:12:50 +01:00 committed by Keavon Chambers
parent 727e5bdeb1
commit 6400953af5
24 changed files with 609 additions and 131 deletions

View file

@ -243,6 +243,10 @@ impl DocumentNodeImplementation {
_ => None,
}
}
pub const fn proto(name: &'static str) -> Self {
Self::Unresolved(NodeIdentifier::new(name))
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, DynAny, specta::Type, Hash)]
@ -812,6 +816,28 @@ impl NodeNetwork {
nodes: nodes.clone(),
})
}
/// Create a [`RecursiveNodeIter`] that iterates over all [`DocumentNode`]s, including ones that are deeply nested.
pub fn recursive_nodes(&self) -> RecursiveNodeIter {
let nodes = self.nodes.iter().map(|(id, node)| (node, self, vec![*id])).collect();
RecursiveNodeIter { nodes }
}
}
/// An iterator over all [`DocumentNode`]s, including ones that are deeply nested.
pub struct RecursiveNodeIter<'a> {
nodes: Vec<(&'a DocumentNode, &'a NodeNetwork, Vec<NodeId>)>,
}
impl<'a> Iterator for RecursiveNodeIter<'a> {
type Item = (&'a DocumentNode, &'a NodeNetwork, Vec<NodeId>);
fn next(&mut self) -> Option<Self::Item> {
let (node, network, path) = self.nodes.pop()?;
if let DocumentNodeImplementation::Network(network) = &node.implementation {
self.nodes.extend(network.nodes.iter().map(|(id, node)| (node, network, [path.as_slice(), &[*id]].concat())));
}
Some((node, network, path))
}
}
#[cfg(test)]