Migrate text layers to nodes (#1155)

* Initial work towards text to node

* Add the text generate node

* Implement live edit

* Fix merge error

* Cleanup text tool

* Implement text

* Fix transforms

* Fix broken image frame

* Double click to edit text

* Fix rendering text on load

* Moving whilst editing

* Better text properties

* Prevent changing vector when there is a Text node

* Push node api

* Use node fn macro

* Stable ids

* Image module as a seperate file

* Explain check for "Input Frame" node

* Code review

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube 2023-04-27 03:07:43 +01:00 committed by Keavon Chambers
parent 271f9d5158
commit ef93f8442a
44 changed files with 1082 additions and 1143 deletions

View file

@ -324,20 +324,19 @@ impl NodeNetwork {
}
/// Appends a new node to the network after the output node and sets it as the new output
pub fn push_node(&mut self, mut node: DocumentNode) -> NodeId {
pub fn push_node(&mut self, mut node: DocumentNode, connect_to_previous: bool) -> NodeId {
let id = self.nodes.len().try_into().expect("Too many nodes in network");
// Set the correct position for the new node
if let Some(pos) = self.nodes.get(&self.original_outputs()[0].node_id).map(|n| n.metadata.position) {
if let Some(pos) = self.original_outputs().first().and_then(|first| self.nodes.get(&first.node_id)).map(|n| n.metadata.position) {
node.metadata.position = pos + IVec2::new(8, 0);
}
if self.outputs.is_empty() {
self.outputs.push(NodeOutput::new(id, 0));
}
let input = NodeInput::node(self.outputs[0].node_id, self.outputs[0].node_output_index);
if node.inputs.is_empty() {
node.inputs.push(input);
} else {
node.inputs[0] = input;
if connect_to_previous && !self.outputs.is_empty() {
let input = NodeInput::node(self.outputs[0].node_id, self.outputs[0].node_output_index);
if node.inputs.is_empty() {
node.inputs.push(input);
} else {
node.inputs[0] = input;
}
}
self.nodes.insert(id, node);
self.outputs = vec![NodeOutput::new(id, 0)];
@ -352,7 +351,7 @@ impl NodeNetwork {
implementation: DocumentNodeImplementation::Unresolved("graphene_core::ops::IdNode".into()),
metadata: DocumentNodeMetadata { position: (0, 0).into() },
};
self.push_node(node)
self.push_node(node, true)
}
/// Adds a Cache and a Clone node to the network
@ -389,7 +388,7 @@ impl NodeNetwork {
}),
metadata: DocumentNodeMetadata { position: (0, 0).into() },
};
self.push_node(node)
self.push_node(node, true)
}
/// Get the nested network given by the path of node ids