Skip to content

Commit

Permalink
Merge pull request #42 from WiseTechGlobal/archer/WI00715545/resizer-…
Browse files Browse the repository at this point in the history
…behaviour

resizing issue when resize to minimal dimension with resizer other than right-bottom resizer
  • Loading branch information
archer0302 authored Jun 18, 2024
2 parents 6478de3 + 1952c74 commit 497ec4e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
12 changes: 10 additions & 2 deletions src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,20 @@ virtual public (Size size, Point position) CalculateNewSizeAndPosition(double de
if (width < NodeModel!.MinimumDimensions.Width)
{
width = NodeModel.MinimumDimensions.Width;
positionX = NodeModel.Position.X;

if (ShouldChangeXPositionOnResize)
{
positionX = OriginalPosition.X + OriginalSize.Width - NodeModel.MinimumDimensions.Width;
}
}
if (height < NodeModel.MinimumDimensions.Height)
{
height = NodeModel.MinimumDimensions.Height;
positionY = NodeModel.Position.Y;

if (ShouldChangeYPositionOnResize)
{
positionY = OriginalPosition.Y + OriginalSize.Height - NodeModel.MinimumDimensions.Height;
}
}

return (new Size(width, height), new Point(positionX, positionY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,31 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize()
var diagram = new TestDiagram();
diagram.SetContainer(new Rectangle(0, 0, 1000, 400));
var node = new NodeModel(position: new Point(0, 0));
node.Size = new Size(100, 200);
node.Size = new Size(300, 300);
node.MinimumDimensions = new Size(50, 100);
var control = new ResizeControl(new BottomLeftResizerProvider());
diagram.Controls.AddFor(node).Add(control);
diagram.SelectModel(node, false);

// before resize
node.Position.X.Should().Be(0);
node.Position.Y.Should().Be(0);
node.Size.Width.Should().Be(100);
node.Size.Height.Should().Be(200);
node.Size.Width.Should().Be(300);
node.Size.Height.Should().Be(300);

// resize
var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
var eventArgs = new PointerEventArgs(0, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
control.OnPointerDown(diagram, node, eventArgs);
eventArgs = new PointerEventArgs(99, -199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
eventArgs = new PointerEventArgs(150, 150, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
diagram.TriggerPointerMove(null, eventArgs);
eventArgs = new PointerEventArgs(300, -300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
eventArgs = new PointerEventArgs(400, -100, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
diagram.TriggerPointerMove(null, eventArgs);

// after resize
node.Position.X.Should().Be(99);
node.Position.X.Should().Be(250);
node.Position.Y.Should().Be(0);
node.Size.Width.Should().Be(0);
node.Size.Height.Should().Be(0);
node.Size.Width.Should().Be(50);
node.Size.Height.Should().Be(100);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,31 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize()
var diagram = new TestDiagram();
diagram.SetContainer(new Rectangle(0, 0, 1000, 400));
var node = new NodeModel(position: new Point(0, 0));
node.Size = new Size(100, 200);
node.Size = new Size(300, 300);
node.MinimumDimensions = new Size(50, 100);
var control = new ResizeControl(new TopLeftResizerProvider());
diagram.Controls.AddFor(node).Add(control);
diagram.SelectModel(node, false);

// before resize
node.Position.X.Should().Be(0);
node.Position.Y.Should().Be(0);
node.Size.Width.Should().Be(100);
node.Size.Height.Should().Be(200);
node.Size.Width.Should().Be(300);
node.Size.Height.Should().Be(300);

// resize
var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
control.OnPointerDown(diagram, node, eventArgs);
eventArgs = new PointerEventArgs(99, 199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
eventArgs = new PointerEventArgs(150, 150, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
diagram.TriggerPointerMove(null, eventArgs);
eventArgs = new PointerEventArgs(300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
eventArgs = new PointerEventArgs(400, 400, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
diagram.TriggerPointerMove(null, eventArgs);

// after resize
node.Position.X.Should().Be(99);
node.Position.Y.Should().Be(199);
node.Size.Width.Should().Be(0);
node.Size.Height.Should().Be(0);
node.Position.X.Should().Be(250);
node.Position.Y.Should().Be(200);
node.Size.Width.Should().Be(50);
node.Size.Height.Should().Be(100);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,31 @@ public void DragResizer_SmallerThanMinSize_SetsNodeToMinSize()
var diagram = new TestDiagram();
diagram.SetContainer(new Rectangle(0, 0, 1000, 400));
var node = new NodeModel(position: new Point(0, 0));
node.Size = new Size(100, 200);
node.Size = new Size(300, 300);
node.MinimumDimensions = new Size(50, 100);
var control = new ResizeControl(new TopRightResizerProvider());
diagram.Controls.AddFor(node).Add(control);
diagram.SelectModel(node, false);

// before resize
node.Position.X.Should().Be(0);
node.Position.Y.Should().Be(0);
node.Size.Width.Should().Be(100);
node.Size.Height.Should().Be(200);
node.Size.Width.Should().Be(300);
node.Size.Height.Should().Be(300);

// resize
var eventArgs = new PointerEventArgs(0, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
var eventArgs = new PointerEventArgs(300, 0, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
control.OnPointerDown(diagram, node, eventArgs);
eventArgs = new PointerEventArgs(-99, 199, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
eventArgs = new PointerEventArgs(150, 150, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
diagram.TriggerPointerMove(null, eventArgs);
eventArgs = new PointerEventArgs(-300, 300, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
eventArgs = new PointerEventArgs(-100, 400, 0, 0, false, false, false, 1, 1, 1, 1, 1, 1, "arrow", true);
diagram.TriggerPointerMove(null, eventArgs);

// after resize
node.Position.X.Should().Be(0);
node.Position.Y.Should().Be(199);
node.Size.Width.Should().Be(0);
node.Size.Height.Should().Be(0);
node.Position.Y.Should().Be(200);
node.Size.Width.Should().Be(50);
node.Size.Height.Should().Be(100);
}

[Fact]
Expand Down

0 comments on commit 497ec4e

Please sign in to comment.