Skip to content

Commit

Permalink
Fix viewport location constraint not working correctly when ResizeToV…
Browse files Browse the repository at this point in the history
…iewport is true
  • Loading branch information
miroiu committed Jul 22, 2024
1 parent 5074b2d commit 71499ee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Nodify/Minimap/Minimap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void OnApplyTemplate()
{
base.OnApplyTemplate();

ItemsHost = GetTemplateChild(ElementItemsHost) as Panel ?? throw new InvalidOperationException($"{ElementItemsHost} is missing or is not of type Panel.");
ItemsHost = GetTemplateChild(ElementItemsHost) as Panel ?? throw new InvalidOperationException($"{ElementItemsHost} is missing or is not of type {nameof(Panel)}.");
}

protected bool IsDragging { get; private set; }
Expand Down Expand Up @@ -132,8 +132,11 @@ private void SetViewportLocation(Point location)

if (MaxViewportOffset.Width != 0 || MaxViewportOffset.Height != 0)
{
position.X = position.X.Clamp(ItemsExtent.Left - ViewportSize.Width / 2 - MaxViewportOffset.Width, ItemsExtent.Right - ViewportSize.Width / 2 + MaxViewportOffset.Width);
position.Y = position.Y.Clamp(ItemsExtent.Top - ViewportSize.Height / 2 - MaxViewportOffset.Height, ItemsExtent.Bottom - ViewportSize.Height / 2 + MaxViewportOffset.Height);
double maxRight = ResizeToViewport ? ItemsExtent.Right : Math.Max(ItemsExtent.Right, ItemsExtent.Left + ViewportSize.Width);
double maxBottom = ResizeToViewport ? ItemsExtent.Bottom : Math.Max(ItemsExtent.Bottom, ItemsExtent.Top + ViewportSize.Height);

position.X = position.X.Clamp(ItemsExtent.Left - ViewportSize.Width / 2 - MaxViewportOffset.Width, maxRight - ViewportSize.Width / 2 + MaxViewportOffset.Width);
position.Y = position.Y.Clamp(ItemsExtent.Top - ViewportSize.Height / 2 - MaxViewportOffset.Height, maxBottom - ViewportSize.Height / 2 + MaxViewportOffset.Height);
}

ViewportLocation = position;
Expand Down

0 comments on commit 71499ee

Please sign in to comment.