diff --git a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs
index 351b1193f..0976f2c14 100644
--- a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs
+++ b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs
@@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Dapplo.Windows.Common.Structs;
@@ -133,6 +134,6 @@ namespace Greenshot.Base.Interfaces.Drawing
///
/// Direction in which to move the container.
/// The surface the container belongs to.
- void SnapToEdge(Direction direction, ISurface surface);
+ void SnapToEdge(Direction direction, Size surfaceSize);
}
}
\ No newline at end of file
diff --git a/src/Greenshot.Editor/Drawing/DrawableContainer.cs b/src/Greenshot.Editor/Drawing/DrawableContainer.cs
index 4961dda01..d681f5eed 100644
--- a/src/Greenshot.Editor/Drawing/DrawableContainer.cs
+++ b/src/Greenshot.Editor/Drawing/DrawableContainer.cs
@@ -690,10 +690,9 @@ namespace Greenshot.Editor.Drawing
///
/// Direction in which to move the container.
/// The surface the container belongs to.
- public void SnapToEdge(Direction direction, ISurface surface)
+ public void SnapToEdge(Direction direction, Size surfaceSize)
{
- Size surfaceBounds = new(surface.Image.Width, surface.Image.Height);
- NativeRectFloat newBounds = GetLocationAfterSnap(direction, this.Bounds, surfaceBounds);
+ NativeRectFloat newBounds = GetLocationAfterSnap(direction, this.Bounds, surfaceSize);
this.MakeBoundsChangeUndoable(allowMerge: false);
this.ApplyBounds(newBounds);
diff --git a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs
index 4baf1ef29..fc7f22635 100644
--- a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs
+++ b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs
@@ -922,9 +922,9 @@ namespace Greenshot.Editor.Drawing
///
public void SnapAllToEdge(Direction direction, ISurface surface)
{
- foreach (IDrawableContainer item in this)
+ foreach (IDrawableContainer container in this)
{
- item.SnapToEdge(direction, surface);
+ SnapContainerToEdge(direction, surface, container);
}
surface.DeselectAllElements();
}
@@ -939,17 +939,19 @@ namespace Greenshot.Editor.Drawing
{
Expansion expansion = GetExpansionFromSize(direction, targetElement.Size);
- targetElement.SnapToEdge(direction, surface);
surface.ResizeCanvas(expansion);
- if (direction == Direction.LEFT || direction == Direction.RIGHT)
- targetElement.SnapToEdge(Direction.TOP, surface);
- else if (direction == Direction.TOP || direction == Direction.BOTTOM)
- targetElement.SnapToEdge(Direction.LEFT, surface);
+ SnapContainerToEdge(direction, surface, targetElement);
surface.DeselectAllElements();
}
+ private void SnapContainerToEdge(Direction direction, ISurface surface, IDrawableContainer targetElement)
+ {
+ Size surfaceBounds = new(surface.Image.Width, surface.Image.Height);
+ targetElement.SnapToEdge(direction, surfaceBounds);
+ }
+
///
/// Calculate the directional expansion needed to accommodate an element of the given size.
///