Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/Controls/InPortContextMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@
<Path Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M 12,10 L -1,5 -1,15 Z"
Data="M 12,6 L -1,1 -1,11 Z"
Fill="White"
Stroke="#999999" />
<Path Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M 2,5 0,5 L0,10 L2,10 Z"
Data="M 2,1 0,1 L0,6 L2,6 Z"
Stretch="None"
Fill="White"
Stroke="White" />
Expand Down
27 changes: 24 additions & 3 deletions src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,20 @@ internal void SetupPortContextMenuPlacement(Popup popup)
/// </summary>
private void ConfigurePopupPlacement(Popup popup, double zoom)
{
var dpiScale = GetDpiScale();

popup.CustomPopupPlacementCallback = (popupSize, targetSize, offset) =>
{
double x;
double y = (targetSize.Height - popupSize.Height) / 2;

if (this is InPortViewModel)
{
x = -popupSize.Width + proxyPortContextMenuOffset * zoom;
x = -popupSize.Width + proxyPortContextMenuOffset * zoom * dpiScale;
}
else
{
x = targetSize.Width - proxyPortContextMenuOffset * zoom;
x = targetSize.Width - proxyPortContextMenuOffset * zoom * dpiScale;
}

return new[] { new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None) };
Expand All @@ -398,6 +400,7 @@ private CustomPopupPlacement[] PlacePortContextMenu(Size popupSize, Size targetS
// The actual zoom here is confusing
// What matters is the zoom factor measured from the scaled : unscaled node size
var zoom = node.WorkspaceViewModel.Zoom;
var dpiScale = GetDpiScale();

double x;
var scaledWidth = autocompletePopupSpacing * targetSize.Width / node.ActualWidth;
Expand All @@ -421,13 +424,31 @@ private CustomPopupPlacement[] PlacePortContextMenu(Size popupSize, Size targetS
var rowOffset = PortModel.Index * PortModel.Height * zoom;
var customNodeOffset = NodeModel.CustomNodeTopBorderHeight * zoom;

var y = popupHeightOffset + headerHeightOffset + portHalfHeight + rowOffset + customNodeOffset;
// popupSize.Height is already DPI-scaled (in screen pixels), so we do NOT apply dpiScale to it
// All other layout values are in logical units and must be multiplied by dpiScale for correct placement
var y = popupHeightOffset + (headerHeightOffset + portHalfHeight + rowOffset + customNodeOffset) * dpiScale;

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

return new[] { placement };
}

private static double GetDpiScale()
{
double dpiScale = 1.0;
try
{
var source = PresentationSource.FromVisual(Application.Current.MainWindow);
dpiScale = source?.CompositionTarget?.TransformToDevice.M22 ?? 1.0;
}
catch
{
// fallback to default DPI scale of 1.0 if anything fails
}

return dpiScale;
}

private void WorkspacePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand Down
Loading