From 00b521aebb2a2be59320a1a9c7aeda1ce4a7e961 Mon Sep 17 00:00:00 2001 From: reddyashish <43763136+reddyashish@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:45:43 -0800 Subject: [PATCH] Cherrypick: DYN-7837 Fix zoom to fit in workspace. (#15653) (#15656) --- .../ViewModels/Core/WorkspaceViewModel.cs | 27 ++++++++++++++----- .../PackageManagerSearchElement.cs | 4 +-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index ade6bc3e252..ecfcdd3583d 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -1501,9 +1501,9 @@ private static bool CanSetZoom(object zoom) /// /// 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. /// /// internal void FitViewInternal(bool toggle = true) @@ -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; diff --git a/src/DynamoPackages/PackageManagerSearchElement.cs b/src/DynamoPackages/PackageManagerSearchElement.cs index 8e653424f46..0e77bfcc1e9 100644 --- a/src/DynamoPackages/PackageManagerSearchElement.cs +++ b/src/DynamoPackages/PackageManagerSearchElement.cs @@ -5,7 +5,7 @@ using Dynamo.Models; using Dynamo.Search.SearchElements; using Dynamo.Utilities; - +using DynamoServices; using Greg.Responses; namespace Dynamo.PackageManager @@ -354,7 +354,7 @@ private List TransformVersionsToVersionInformation(Greg.Resp } catch (Exception ex) { - Console.WriteLine(ex.ToString()); + DynamoConsoleLogger.OnLogMessageToDynamoConsole(ex.ToString()); return null; } }