Skip to content

Commit

Permalink
DYN-7837: Fix zoom to fit in workspace. (#15653)
Browse files Browse the repository at this point in the history
  • Loading branch information
reddyashish authored Nov 14, 2024
1 parent 421e48e commit f233986
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,9 +1501,9 @@ private static bool CanSetZoom(object zoom)
/// <summary>
/// Zoom around current selection
/// _fitViewActualZoomToggle is used internally to toggle
/// between the default 1.0 zoom level and the intended zoom around selection
/// between the default 1.0 zoom level and the intended zoom around selection
/// The optional toggle boolean is introduced to avoid this behavior and only zoom around the selection
/// no matter how many times the operation is performed
/// no matter how many times the operation is performed.
/// </summary>
/// <param name="toggle"></param>
internal void FitViewInternal(bool toggle = true)
Expand Down Expand Up @@ -1543,13 +1543,26 @@ internal void FitViewInternal(bool toggle = true)
maxX = Math.Max(model.X + model.Width, maxX);
minY = Math.Min(model.Y, minY);
maxY = Math.Max(model.Y + model.Height, maxY);
}

}
}

double focusWidth;
double focusHeight;

// If toggle is true, zoom to fit in the whole workspace view,
// else zoom around the selected element by adding a padding factor.
if (toggle)
{
focusWidth = maxX - minX;
focusHeight = maxY - minY;
}
else
{
// Add padding to the calculated bounding box for better visibility
focusWidth = (maxX - minX) * Configurations.ZoomToFitPaddingFactor;
focusHeight = (maxY - minY) * Configurations.ZoomToFitPaddingFactor;

// Add padding to the calculated bounding box for better visibility
double focusWidth = (maxX - minX) * Configurations.ZoomToFitPaddingFactor;
double focusHeight = (maxY - minY) * Configurations.ZoomToFitPaddingFactor;
}

// Adjust offset to ensure the view is centered with the padding
double offsetX = minX - (focusWidth - (maxX - minX)) / 2.0;
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoPackages/PackageManagerSearchElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Dynamo.Models;
using Dynamo.Search.SearchElements;
using Dynamo.Utilities;

using DynamoServices;
using Greg.Responses;

namespace Dynamo.PackageManager
Expand Down Expand Up @@ -354,7 +354,7 @@ private List<VersionInformation> TransformVersionsToVersionInformation(Greg.Resp
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
DynamoConsoleLogger.OnLogMessageToDynamoConsole(ex.ToString());
return null;
}
}
Expand Down

0 comments on commit f233986

Please sign in to comment.