mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-18 18:38:05 +08:00
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:
@@ -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)]
|
||||
|
||||
@@ -10,7 +10,6 @@ pub struct Compiler {}
|
||||
impl Compiler {
|
||||
pub fn compile(&self, mut network: NodeNetwork, resolve_inputs: bool) -> impl Iterator<Item = ProtoNetwork> {
|
||||
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
||||
network.generate_node_paths(&[]);
|
||||
network.resolve_extract_nodes();
|
||||
println!("flattening");
|
||||
for id in node_ids {
|
||||
|
||||
@@ -156,6 +156,7 @@ impl ProtoNode {
|
||||
|
||||
self.identifier.name.hash(&mut hasher);
|
||||
self.construction_args.hash(&mut hasher);
|
||||
self.document_node_path.hash(&mut hasher);
|
||||
match self.input {
|
||||
ProtoNodeInput::None => "none".hash(&mut hasher),
|
||||
ProtoNodeInput::ShortCircut(ref ty) => {
|
||||
@@ -629,12 +630,12 @@ mod test {
|
||||
assert_eq!(
|
||||
ids,
|
||||
vec![
|
||||
10739226043134366700,
|
||||
17332796976541881019,
|
||||
7897288931440576543,
|
||||
7388412494950743023,
|
||||
359700384277940942,
|
||||
12822947441562012352
|
||||
4471348669260178714,
|
||||
12892313567093808068,
|
||||
6883586777044498729,
|
||||
13841339389284532934,
|
||||
4412916056300566478,
|
||||
15358108940336208665
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user