Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Resizer Provider #28

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { get; set; }
protected Point? _originalPosition { get; set; }
private double? _lastClientX;
private double? _lastClientY;
private NodeModel? _nodeModel = null;
protected NodeModel? _nodeModel { get; set; }
private double _totalMovedX = 0;
private double _totalMovedY = 0;
private Diagram? _diagram;
protected Diagram? _diagram { get; set; }

abstract public bool ShouldChangeXPositionOnResize { get; }
abstract public bool ShouldChangeYPositionOnResize { get; }
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading