From e3a4577442d9aa79fe1ce93b0a19279be5b39308 Mon Sep 17 00:00:00 2001 From: Renan Alvarenga Date: Tue, 5 Mar 2024 15:18:43 +1100 Subject: [PATCH 1/2] Addressed PR comments --- .../Positions/Resizing/ResizerProvider.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs index e720715d..dcbebdb6 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs @@ -9,14 +9,14 @@ public abstract class ResizerProvider : IPositionProvider { abstract public string? Class { get; } - private Size? _originalSize = null; - private Point? _originalPosition = null; + protected Size? _originalSize = null; + protected Point? _originalPosition = null; private double? _lastClientX; private double? _lastClientY; - private NodeModel? _nodeModel = null; + protected NodeModel? _nodeModel = null; private double _totalMovedX = 0; private double _totalMovedY = 0; - private Diagram? _diagram; + protected Diagram? _diagram; abstract public bool ShouldChangeXPositionOnResize { get; } abstract public bool ShouldChangeYPositionOnResize { get; } @@ -27,7 +27,7 @@ public abstract class ResizerProvider : IPositionProvider abstract public Point? GetPosition(Model model); - virtual public void ResizeNode(double deltaX, double deltaY) + virtual public (Size size, Point position) CalculateNewSizeAndPosition(double deltaX, double deltaY) { _totalMovedX += deltaX; _totalMovedY += deltaY; @@ -49,8 +49,13 @@ virtual public void ResizeNode(double deltaX, double deltaY) positionY = _nodeModel.Position.Y; } - _nodeModel.SetPosition(positionX, positionY); - _nodeModel.SetSize(width, height); + return (new Size(width, height), new Point(positionX, positionY)); + } + + virtual public void SetSizeAndPosition(Size size, Point position) + { + _nodeModel!.SetPosition(position.X, position.Y); + _nodeModel.SetSize(size.Width, size.Height); } virtual public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs e) @@ -79,14 +84,16 @@ virtual public void OnPointerMove(Model? model, PointerEventArgs e) _lastClientX = e.ClientX; _lastClientY = e.ClientY; - ResizeNode(deltaX, deltaY); + var result = CalculateNewSizeAndPosition(deltaX, deltaY); + SetSizeAndPosition(result.size, result.position); } virtual public void OnPanChanged(double deltaX, double deltaY) { if (_nodeModel is null) return; - ResizeNode(deltaX, deltaY); + var result = CalculateNewSizeAndPosition(deltaX, deltaY); + SetSizeAndPosition(result.size, result.position); } virtual public void OnResizeEnd(Model? model, PointerEventArgs args) From 8967512d86263f9dff91e9e974aae3a2be8d1c65 Mon Sep 17 00:00:00 2001 From: Renan Alvarenga Date: Wed, 6 Mar 2024 15:21:13 +1100 Subject: [PATCH 2/2] Protected fields are now properties --- .../Positions/Resizing/ResizerProvider.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs b/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs index dcbebdb6..7ca91d90 100644 --- a/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs +++ b/src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs @@ -9,14 +9,14 @@ public abstract class ResizerProvider : IPositionProvider { abstract public string? Class { get; } - protected Size? _originalSize = null; - protected Point? _originalPosition = null; + protected Size? _originalSize { get; set; } + protected Point? _originalPosition { get; set; } private double? _lastClientX; private double? _lastClientY; - protected NodeModel? _nodeModel = null; + protected NodeModel? _nodeModel { get; set; } private double _totalMovedX = 0; private double _totalMovedY = 0; - protected Diagram? _diagram; + protected Diagram? _diagram { get; set; } abstract public bool ShouldChangeXPositionOnResize { get; } abstract public bool ShouldChangeYPositionOnResize { get; }