Skip to content

Commit

Permalink
DYN-4308 Input and output port menu Y location (#13683)
Browse files Browse the repository at this point in the history
* DYN-4308 Input and output port menu is tiny when zoomed in and gets bigger when zoomed out

- redo of the Y position calculation

* Removed unused variables

- a small fix
  • Loading branch information
dnenov authored Jan 20, 2023
1 parent 08a2a32 commit 983da29
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
Expand Down Expand Up @@ -347,11 +347,12 @@ private CustomPopupPlacement[] PlaceAutocompletePopup(Size popupSize, Size targe

private CustomPopupPlacement[] PlacePortContextMenu(Size popupSize, Size targetSize, Point offset)
{
// The actual zoom here is confusing
// What matters is the zoom factor measured from the scaled : unscaled node size
var zoom = node.WorkspaceViewModel.Zoom;

double x;
var scaledWidth = autocompletePopupSpacing * targetSize.Width / node.ActualWidth;
var scaledHeight = targetSize.Height / node.ActualHeight;

if (PortModel.PortType == PortType.Input)
{
Expand All @@ -363,10 +364,15 @@ private CustomPopupPlacement[] PlacePortContextMenu(Size popupSize, Size targetS
// Offset popup to the right by node width and spacing from left edge of node.
x = scaledWidth + targetSize.Width;
}
// Offset popup down from the upper edge of the node by the node header and corresponding to the respective port.
// Scale the absolute heights by the target height (passed to the callback) and the actual height of the node.
var absoluteHeight = NodeModel.HeaderHeight + PortModel.Index * PortModel.Height;
var y = absoluteHeight * scaledHeight;
// Important - while zooming in and out, Node elements are scaled, while popup is not
// Calculate absolute popup halfheight to deduct from the overal y pos
// Then add the header, port height and port index position
var popupHeightOffset = - popupSize.Height * 0.5;
var headerHeightOffset = 2 * NodeModel.HeaderHeight * zoom;
var portHalfHeight = PortModel.Height * 0.5 * zoom;
var rowOffset = PortModel.Index * (1.5 * PortModel.Height) * zoom;

var y = popupHeightOffset + headerHeightOffset + portHalfHeight + rowOffset;

var placement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None);

Expand Down

0 comments on commit 983da29

Please sign in to comment.