Skip to content
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

Adjust the node position when a Node-Autocompletion element is connected. #11775

Merged
merged 4 commits into from
Jun 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/DynamoCoreWpf/ViewModels/Search/NodeSearchElementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class NodeSearchElementViewModel : ViewModelBase, ISearchEntryViewModel
private bool isSelected;
private SearchViewModel searchViewModel;
private IDisposable undoRecorderGroup;
private int spacingBetweenNodes = 50;
private int spacingforHigherWidthNodes = 450;

public event RequestBitmapSourceHandler RequestBitmapSource;
public void OnRequestBitmapSource(IconRequestEventArgs e)
Expand Down Expand Up @@ -268,26 +270,33 @@ protected virtual void CreateAndConnectToPort(object parameter)
var id = Guid.NewGuid();

var adjustedX = initialNodeVm.X;
var adjustedY = initialNodeVm.Y;

var createAsDownStreamNode = portModel.PortType == PortType.Output;
// Placing the new node based on which port it is connecting to.
if (createAsDownStreamNode)
{
// Placing the new node to the right of initial node
adjustedX += initialNode.Width + 50;
adjustedX += initialNode.Width + spacingBetweenNodes;

// Create a new node based on node creation name and connection ports
dynamoViewModel.ExecuteCommand(new DynamoModel.CreateAndConnectNodeCommand(id, initialNode.GUID,
Model.CreationName, 0, Model.AutoCompletionNodeElementInfo.PortToConnect, adjustedX, 0, createAsDownStreamNode, false, true));
Model.CreationName, 0, Model.AutoCompletionNodeElementInfo.PortToConnect, adjustedX, adjustedY, createAsDownStreamNode, false, true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we made the adjusted Y 0 on purpose, @aparajit-pratap @zeusongit can you confirm? Maybe we thought the auto layout algorithm will simply solve that? Anyway, the solution here looks simple enough to be consistent

Copy link
Contributor

@zeusongit zeusongit Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some back-and-forth on this I remember. But I dont recall the problem. Anyway it seems to work fine at the moment.

}
else
{
// Placing the new node to the left of initial node
adjustedX -= initialNode.Width + 50;
adjustedX -= initialNode.Width + spacingBetweenNodes;

// If the new node is a slider input node, adjust the position on X-axis to compensate for higher width of the slider node.
if (Model.CreationName.Contains("Slider"))
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
adjustedX -= spacingforHigherWidthNodes;
}

// Create a new node based on node creation name and connection ports
dynamoViewModel.ExecuteCommand(new DynamoModel.CreateAndConnectNodeCommand(id, initialNode.GUID,
Model.CreationName, 0, portModel.Index, adjustedX, 0, createAsDownStreamNode, false, true));
Model.CreationName, 0, portModel.Index, adjustedX, adjustedY, createAsDownStreamNode, false, true));
}

var inputNodes = initialNode.InputNodes.Values.Where(x => x != null).Select(y => y.Item2);
Expand Down