Generalize layers as merge nodes to enable adjustment layers (#1712)

* WIP, backward traversal issues

* Fix some tool issues

* Remove debugging

* Change some indices

* WIP: new artboard node

* WIP: add artboard node

* WIP: Artboard node and create_artboard

* WIP: Artboard node implementation complete

* WIP: Artboards input for output node

* Complete Artboard node

* Generalize LayerNodeIdentifier,  monitor_nodes support for Artboard node, adjust ResizeArtboard/ClearArtboards, move alias validation to Rust

* Fix misaligned artboard click targets

* Generalize/clarify create_layer and insert_between

* non-negative dimensions for resize_artboard

* Show artboards in layer panel

* Generalize create_layer for layer output node

* Generalize delete_layer/delete_artboard to NodeGraphMessage::DeleteNodes. Fixed upstream flow Iter

* remove old primary_input function

* Vertical node visuals, remove is_layer function, rename Layer node to Merge node, toggle display as layer

exposed_value_count type fix

Vertical node visuals, remove is_layer function, rename Layer node to Merge node, toggle display as layer

* Fix demo artwork

* Layer display context menu

* Automatically select artboard, fix warnings

* Improvements to context menu and layer invariant enforcement

* Remove display_as_layer and update load_structure

* Improve load_structure to show more layers, improve FlowIter, improve layer naming, layer rearrangement validation.

* Clean up demo artwork using generalized layers

* Improve design of Layers panel and graph nodes

* MoveSelectedLayersTo rewrite to support generalized layer nodes

* Include artboards in deepest_common_ancestor, fix resize_artboard/delete_artboard, sync artboard tool to layer panel

* MoveSelectedLayersTo adjustments

* Sync non layer node visibility with metadata

* Include non layer nodes when moving/creating layer

* Fix group layers and get_post_node_with_index

* Include non layer nodes in UngroupSelectedLayers

* GroupSelected for all selected nodes, UnGroupSelected position adjustments

* Add grouping for layers in different folders

* Fix hidden layers

* Prevent node from connecting to itself, fix undo automatic node insertion,

* Fix undo CreateEmptyFolder, fix grouping nested layer nodes

* Formatting

* Remove test and check if node is layer from network

* Fix undo group layers

* Check off roadmap

* MoveUpstreamSiblingsToChild adjustments

* Replace tabs with spaces, remove mut from argument

* Final code review pass

---------

Co-authored-by: 0hypercube <0hypercube@gmail.com>
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
adamgerhant
2024-04-30 23:03:42 -07:00
committed by GitHub
co-authored by 0hypercube Keavon Chambers
parent beb88d280c
commit 8d83fa7079
41 changed files with 1712 additions and 825 deletions
@@ -157,11 +157,11 @@ pub fn get_opacity(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -
}
pub fn get_fill_id(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<NodeId> {
NodeGraphLayer::new(layer, document_network).node_id("Fill")
NodeGraphLayer::new(layer, document_network).upstream_node_id_from_name("Fill")
}
pub fn get_text_id(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<NodeId> {
NodeGraphLayer::new(layer, document_network).node_id("Text")
NodeGraphLayer::new(layer, document_network).upstream_node_id_from_name("Text")
}
/// Gets properties from the Text node
@@ -233,21 +233,21 @@ impl<'a> NodeGraphLayer<'a> {
}
}
/// Return an iterator up the primary flow of the layer
pub fn primary_layer_flow(&self) -> impl Iterator<Item = (&'a DocumentNode, NodeId)> {
self.node_graph.upstream_flow_back_from_nodes(vec![self.layer_node], true)
/// Return an iterator up the horizontal flow of the layer
pub fn horizontal_layer_flow(&self) -> impl Iterator<Item = (&'a DocumentNode, NodeId)> {
self.node_graph.upstream_flow_back_from_nodes(vec![self.layer_node], graph_craft::document::FlowType::HorizontalFlow)
}
/// Node id of a node if it exists in the layer's primary flow
pub fn node_id(&self, node_name: &str) -> Option<NodeId> {
self.primary_layer_flow().find(|(node, _id)| node.name == node_name).map(|(_node, id)| id)
pub fn upstream_node_id_from_name(&self, node_name: &str) -> Option<NodeId> {
self.horizontal_layer_flow().find(|(node, _)| node.name == node_name).map(|(_, id)| id)
}
/// Find all of the inputs of a specific node within the layer's primary flow, up until the next layer is reached.
pub fn find_node_inputs(&self, node_name: &str) -> Option<&'a Vec<NodeInput>> {
self.primary_layer_flow()
.skip(1)
.take_while(|(node, _)| !node.is_layer())
self.horizontal_layer_flow()
.skip(1)// Skip self
.take_while(|(node, _)| !node.is_layer)
.find(|(node, _)| node.name == node_name)
.map(|(node, _id)| &node.inputs)
}
@@ -432,16 +432,16 @@ pub fn are_manipulator_handles_colinear<Id: bezier_rs::Identifier>(group: &bezie
pub fn get_layer_snap_points(layer: LayerNodeIdentifier, snap_data: &SnapData, points: &mut Vec<SnapCandidatePoint>) {
let document = snap_data.document;
if document.metadata().is_artboard(layer) {
} else if document.metadata().is_folder(layer) {
return;
}
if document.metadata().is_folder(layer) {
for child in layer.descendants(document.metadata()) {
get_layer_snap_points(child, snap_data, points);
}
} else {
// Skip empty paths
if document.metadata.layer_outline(layer).next().is_none() {
return;
}
} else if document.metadata.layer_outline(layer).next().is_some() {
let to_document = document.metadata.transform_to_document(layer);
for subpath in document.metadata.layer_outline(layer) {
subpath_anchor_snap_points(layer, subpath, snap_data, points, to_document);
@@ -3,7 +3,6 @@ use crate::application::generate_uuid;
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
use crate::messages::tool::common_functionality::graph_modification_utils::is_layer_fed_by_node_of_name;
use crate::messages::tool::common_functionality::snapping::SnapManager;
use crate::messages::tool::common_functionality::transformation_cage::*;
@@ -24,6 +23,7 @@ pub enum ArtboardToolMessage {
Overlays(OverlayContext),
// Tool-specific messages
UpdateSelectedArtboard,
DeleteSelected,
NudgeSelected { delta_x: f64, delta_y: f64 },
PointerDown,
@@ -125,7 +125,7 @@ impl ArtboardToolData {
let mut intersections = document
.click_xray(input.mouse.position)
.filter(|&layer| is_layer_fed_by_node_of_name(layer, &document.network, "Artboard"));
.filter(|&layer| document.network.nodes.get(&layer.to_node()).map_or(false, |document_node| document_node.is_artboard()));
if let Some(intersection) = intersections.next() {
self.selected_artboard = Some(intersection);
@@ -136,6 +136,8 @@ impl ArtboardToolData {
bounding_box_manager.transform = document.metadata().document_to_viewport;
}
responses.add_front(NodeGraphMessage::SelectedNodesSet { nodes: vec![intersection.to_node()] });
true
} else {
self.selected_artboard = None;
@@ -278,10 +280,8 @@ impl Fsm for ArtboardToolFsmState {
});
} else {
let id = NodeId(generate_uuid());
tool_data.selected_artboard = Some(LayerNodeIdentifier::new_unchecked(id));
//tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(), true, true);
//tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
tool_data.selected_artboard = Some(LayerNodeIdentifier::new_unchecked(id));
responses.add(GraphOperationMessage::NewArtboard {
id,
@@ -377,11 +377,13 @@ impl Fsm for ArtboardToolFsmState {
ArtboardToolFsmState::Ready
}
(_, ArtboardToolMessage::UpdateSelectedArtboard) => {
tool_data.selected_artboard = document.selected_nodes.selected_layers(document.metadata()).find(|layer| document.metadata().is_artboard(*layer));
self
}
(_, ArtboardToolMessage::DeleteSelected) => {
if let Some(artboard) = tool_data.selected_artboard.take() {
let id = artboard.to_node();
responses.add(GraphOperationMessage::DeleteArtboard { id });
}
tool_data.selected_artboard.take();
responses.add(NodeGraphMessage::DeleteSelectedNodes { reconnect: true });
ArtboardToolFsmState::Ready
}
(_, ArtboardToolMessage::NudgeSelected { delta_x, delta_y }) => {
@@ -267,8 +267,8 @@ impl BrushToolData {
};
self.layer = Some(layer);
for (node, node_id) in document.network().upstream_flow_back_from_nodes(vec![layer.to_node()], true) {
if node.name == "Brush" {
for (node, node_id) in document.network().upstream_flow_back_from_nodes(vec![layer.to_node()], graph_craft::document::FlowType::HorizontalFlow) {
if node.name == "Brush" && node_id != layer.to_node() {
let points_input = node.inputs.get(2)?;
let NodeInput::Value {
tagged_value: TaggedValue::BrushStrokes(strokes),
@@ -325,7 +325,7 @@ impl SelectToolData {
document.network(),
&document
.network()
.upstream_flow_back_from_nodes(vec![node], false)
.upstream_flow_back_from_nodes(vec![node], graph_craft::document::FlowType::UpstreamFlow)
.enumerate()
.map(|(index, (_, node_id))| (node_id, NodeId(index as u64)))
.collect(),
@@ -365,8 +365,9 @@ impl SelectToolData {
// Delete the duplicated layers
for layer_ancestors in document.metadata().shallowest_unique_layers(self.layers_dragging.iter().copied()) {
responses.add(GraphOperationMessage::DeleteLayer {
id: layer_ancestors.last().unwrap().to_node(),
responses.add(NodeGraphMessage::DeleteNodes {
node_ids: vec![layer_ancestors.last().unwrap().to_node()],
reconnect: true,
});
}