Skip to content

Add grid snapping to graph imports/exports; improve layer panel drag into/between insertion; better preserve graph space on reordering #1911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 11, 2024
Merged
Prev Previous commit
Next Next commit
Final previewing fixes
  • Loading branch information
adamgerhant authored and Keavon committed Aug 10, 2024
commit 777c449b556abd159d45cc2f1df782f8c0d0961e
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
if let Some(disconnecting) = &self.disconnecting {
responses.add(DocumentMessage::StartTransaction);
let mut disconnect_root_node = false;
if let Previewing::Yes {
root_node_to_restore: Some(root_node_to_restore),
} = network_interface.previewing(selection_network_path)
{
if *disconnecting == InputConnector::Export(0) {
if let Previewing::Yes { root_node_to_restore } = network_interface.previewing(selection_network_path) {
if root_node_to_restore.is_some() && *disconnecting == InputConnector::Export(0) {
disconnect_root_node = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2376,11 +2376,7 @@ impl NodeNetworkInterface {
NodeTypePersistentMetadata::Layer(_) => {
// If the layer feeds into the bottom input of layer, set its position to stack at its previous y position
if *input_index == 0 {
let Some(downstream_node_position) = self.position(downstream_node_id, network_path) else {
log::error!("Could not get downstream node position in set_input for node {downstream_node_id}");
return;
};
self.set_stack_position(upstream_node_id, (current_node_position.y - downstream_node_position.y - 3).max(0) as u32, network_path);
self.set_stack_position_calculated_offset(upstream_node_id, downstream_node_id, network_path);
} else {
self.set_absolute_position(upstream_node_id, network_path, current_node_position);
}
Expand Down Expand Up @@ -2455,11 +2451,40 @@ impl NodeNetworkInterface {
return;
}

// If the node upstream from the disconnected input is a chain, then break the chain by setting it to absolute positioning
if let NodeInput::Node { node_id: upstream_node_id, .. } = &current_input {
if let NodeInput::Node {
node_id: upstream_node_id,
output_index,
..
} = &current_input
{
// If the node upstream from the disconnected input is a chain, then break the chain by setting it to absolute positioning
if self.is_chain(upstream_node_id, network_path) {
self.set_upstream_chain_to_absolute(upstream_node_id, network_path);
}
// If the node upstream from the disconnected input has an outward wire to the bottom of a layer, set it back to stack positioning
if self.is_layer(upstream_node_id, network_path) {
let Some(outward_wires) = self
.outward_wires(network_path)
.and_then(|outward_wires| outward_wires.get(&OutputConnector::node(*upstream_node_id, *output_index)))
else {
log::error!("Could not get outward wires in disconnect_input");
return;
};
let mut other_outward_wires = outward_wires.iter().filter(|outward_wire| *outward_wire != input_connector);
if let Some(other_outward_wire) = other_outward_wires.next().cloned() {
if other_outward_wires.next().is_none() {
if let InputConnector::Node {
node_id: downstream_node_id,
input_index,
} = other_outward_wire
{
if self.is_layer(&downstream_node_id, network_path) && input_index == 0 {
self.set_stack_position_calculated_offset(upstream_node_id, &downstream_node_id, network_path);
}
}
}
}
}
}

let tagged_value = TaggedValue::from_type(&self.input_type(input_connector, network_path));
Expand Down Expand Up @@ -2820,11 +2845,7 @@ impl NodeNetworkInterface {
// If a node is set to a layer
if let Some(upstream_sibling_id) = upstream_sibling_id {
if self.is_layer(&upstream_sibling_id, network_path) {
let (Some(toggled_node_position), Some(upstream_node_position)) = (self.position(node_id, network_path), self.position(&upstream_sibling_id, network_path)) else {
log::error!("Could not get downstream node position in set_to_node_or_layer");
return;
};
self.set_stack_position(&upstream_sibling_id, (upstream_node_position.y - toggled_node_position.y - 3).max(0) as u32, network_path);
self.set_stack_position_calculated_offset(&upstream_sibling_id, node_id, network_path);
} else {
self.set_upstream_chain_to_absolute(&upstream_sibling_id, network_path);
}
Expand Down Expand Up @@ -2928,6 +2949,11 @@ impl NodeNetworkInterface {
if root_node_to_restore.node_id == toggle_id {
new_export = Some(OutputConnector::node(toggle_id, 0));
new_previewing_state = Previewing::Yes { root_node_to_restore: None };
} else {
// Root node to restore does not change
new_previewing_state = Previewing::Yes {
root_node_to_restore: Some(root_node_to_restore),
};
}
}
// There is a dashed line without a solid line.
Expand Down Expand Up @@ -2994,6 +3020,20 @@ impl NodeNetworkInterface {
}
}

/// Sets the position of a node to a stack position without changing its y offset
pub fn set_stack_position_calculated_offset(&mut self, node_id: &NodeId, downstream_layer: &NodeId, network_path: &[NodeId]) {
let Some(node_position) = self.position(node_id, network_path) else {
log::error!("Could not get node position for node {node_id}");
return;
};
let Some(downstream_position) = self.position(downstream_layer, network_path) else {
log::error!("Could not get downstream position for node {downstream_layer}");
return;
};

self.set_stack_position(node_id, (node_position.y - downstream_position.y - 3).max(0) as u32, network_path);
}

/// Sets the position of a node to a chain position
pub fn set_chain_position(&mut self, node_id: &NodeId, network_path: &[NodeId]) {
let Some(node_metadata) = self.node_metadata_mut(node_id, network_path) else {
Expand Down
10 changes: 1 addition & 9 deletions editor/src/messages/portfolio/portfolio_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
};
// If the downstream node is a layer and the input is the first input and the current layer is not in a stack
if input_index == 0 && document.network_interface.is_layer(&downstream_node, &[]) && document.network_interface.is_absolute(&layer.to_node(), &[]) {
let (Some(layer_position), Some(downstream_position)) =
(document.network_interface.position(&layer.to_node(), &[]), document.network_interface.position(&downstream_node, &[]))
else {
log::error!("Could not get downstream node position in PortfolioMessage::OpenDocumentFileWithId");
return;
};
document
.network_interface
.set_stack_position(&layer.to_node(), (layer_position.y - downstream_position.y - 3).max(0) as u32, &[]);
document.network_interface.set_stack_position_calculated_offset(&layer.to_node(), &downstream_node, &[]);
}
}

Expand Down