mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Migrate the Text tool to the document graph (#1435)
* Update text tool to document graph * Fix selection issue * Log graph reruns and text node evals * Hash to set node * Fix let node crash * Fix loading document with fonts * Allow pressing enter to edit * Cleanup * Code review nits --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -41,6 +41,9 @@ pub struct DocumentNode {
|
||||
pub metadata: DocumentNodeMetadata,
|
||||
#[serde(default)]
|
||||
pub skip_deduplication: bool,
|
||||
/// Used as a hash of the graph input where applicable. This ensures that protonodes that depend on the graph's input are always regenerated.
|
||||
#[serde(default)]
|
||||
pub hash: u64,
|
||||
pub path: Option<Vec<NodeId>>,
|
||||
}
|
||||
|
||||
@@ -103,6 +106,7 @@ impl DocumentNode {
|
||||
construction_args: args,
|
||||
document_node_path: self.path.unwrap_or(Vec::new()),
|
||||
skip_deduplication: self.skip_deduplication,
|
||||
hash: self.hash,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,6 +197,7 @@ pub struct ProtoNode {
|
||||
pub identifier: NodeIdentifier,
|
||||
pub document_node_path: Vec<NodeId>,
|
||||
pub skip_deduplication: bool,
|
||||
pub hash: u64,
|
||||
}
|
||||
|
||||
/// A ProtoNodeInput represents the input of a node in a ProtoNetwork.
|
||||
@@ -235,6 +236,7 @@ impl ProtoNode {
|
||||
if self.skip_deduplication {
|
||||
self.document_node_path.hash(&mut hasher);
|
||||
}
|
||||
self.hash.hash(&mut hasher);
|
||||
std::mem::discriminant(&self.input).hash(&mut hasher);
|
||||
match self.input {
|
||||
ProtoNodeInput::None => (),
|
||||
@@ -256,6 +258,7 @@ impl ProtoNode {
|
||||
input: ProtoNodeInput::None,
|
||||
document_node_path: path,
|
||||
skip_deduplication: false,
|
||||
hash: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +364,7 @@ impl ProtoNetwork {
|
||||
input,
|
||||
document_node_path: path,
|
||||
skip_deduplication: false,
|
||||
hash: 0,
|
||||
},
|
||||
));
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ impl BorrowTree {
|
||||
old_nodes.remove(&id);
|
||||
}
|
||||
self.source_map.retain(|_, nid| !old_nodes.contains(nid));
|
||||
self.nodes.retain(|nid, _| !old_nodes.contains(nid));
|
||||
Ok(old_nodes.into_iter().collect())
|
||||
}
|
||||
|
||||
|
||||
@@ -730,9 +730,47 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
|
||||
register_node!(graphene_core::vector::RepeatNode<_, _>, input: VectorData, params: [DVec2, u32]),
|
||||
register_node!(graphene_core::vector::BoundingBoxNode, input: VectorData, params: []),
|
||||
register_node!(graphene_core::vector::CircularRepeatNode<_, _, _>, input: VectorData, params: [f32, f32, u32]),
|
||||
register_node!(graphene_core::transform::CullNode<_>, input: Footprint, params: [VectorData]),
|
||||
vec![(
|
||||
NodeIdentifier::new("graphene_core::transform::CullNode<_>"),
|
||||
|args| {
|
||||
Box::pin(async move {
|
||||
let mut args = args.clone();
|
||||
args.reverse();
|
||||
let node = <graphene_core::transform::CullNode<_>>::new(graphene_std::any::input_node::<VectorData>(args.pop().expect("Not enough arguments provided to construct node")));
|
||||
let any: DynAnyNode<Footprint, _, _> = graphene_std::any::DynAnyNode::new(node);
|
||||
Box::new(any) as Box<dyn for<'i> NodeIO<'i, graph_craft::proto::Any<'i>, Output = (core::pin::Pin<Box<dyn core::future::Future<Output = graph_craft::proto::Any<'i>> + 'i>>)> + '_>
|
||||
})
|
||||
},
|
||||
{
|
||||
let node = <graphene_core::transform::CullNode<_>>::new((graphene_std::any::PanicNode::<(), VectorData>::new()));
|
||||
let params = vec![fn_type!((), VectorData)];
|
||||
let mut node_io = <graphene_core::transform::CullNode<_> as NodeIO<'_, Footprint>>::to_node_io(&node, params);
|
||||
node_io.input = concrete!(<Footprint as StaticType>::Static);
|
||||
node_io
|
||||
},
|
||||
)],
|
||||
register_node!(graphene_core::transform::CullNode<_>, input: Footprint, params: [graphene_core::Artboard]),
|
||||
register_node!(graphene_core::transform::CullNode<_>, input: Footprint, params: [graphene_core::GraphicGroup]),
|
||||
vec![(
|
||||
NodeIdentifier::new("graphene_core::transform::CullNode<_>"),
|
||||
|args| {
|
||||
Box::pin(async move {
|
||||
let mut args = args.clone();
|
||||
args.reverse();
|
||||
let node = <graphene_core::transform::CullNode<_>>::new(graphene_std::any::input_node::<graphene_core::GraphicGroup>(
|
||||
args.pop().expect("Not enough arguments provided to construct node"),
|
||||
));
|
||||
let any: DynAnyNode<Footprint, _, _> = graphene_std::any::DynAnyNode::new(node);
|
||||
Box::new(any) as Box<dyn for<'i> NodeIO<'i, graph_craft::proto::Any<'i>, Output = (core::pin::Pin<Box<dyn core::future::Future<Output = graph_craft::proto::Any<'i>> + 'i>>)> + '_>
|
||||
})
|
||||
},
|
||||
{
|
||||
let node = <graphene_core::transform::CullNode<_>>::new((graphene_std::any::PanicNode::<(), graphene_core::GraphicGroup>::new()));
|
||||
let params = vec![fn_type!((), graphene_core::GraphicGroup)];
|
||||
let mut node_io = <graphene_core::transform::CullNode<_> as NodeIO<'_, Footprint>>::to_node_io(&node, params);
|
||||
node_io.input = concrete!(<Footprint as StaticType>::Static);
|
||||
node_io
|
||||
},
|
||||
)],
|
||||
register_node!(graphene_std::raster::SampleNode<_>, input: Footprint, params: [ImageFrame<Color>]),
|
||||
register_node!(graphene_std::raster::MandelbrotNode, input: Footprint, params: []),
|
||||
register_node!(graphene_core::vector::ResamplePoints<_>, input: VectorData, params: [f64]),
|
||||
|
||||
Reference in New Issue
Block a user