Skip to content

Commit

Permalink
Fix bug where moving a single grandchild in groups doesn't move the g…
Browse files Browse the repository at this point in the history
…randfather as well (confusing explanation?)
  • Loading branch information
zHaytam committed Oct 16, 2022
1 parent 15f6d1d commit 09c9a8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Blazor.Diagrams.Core/Models/GroupModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Blazor.Diagrams.Core.Extensions;
using Blazor.Diagrams.Core.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -52,6 +53,7 @@ public void RemoveChild(NodeModel child)

public override void SetPosition(double x, double y)
{
Console.WriteLine($"({(Group == null ? "Parent" : "Child")}) SetPosition {x:00} {y:00}");
var deltaX = x - Position.X;
var deltaY = y - Position.Y;
base.SetPosition(x, y);
Expand All @@ -65,10 +67,13 @@ public override void SetPosition(double x, double y)

public override void UpdatePositionSilently(double deltaX, double deltaY)
{
Console.WriteLine($"({(Group == null ? "Parent" : "Child")}) UpdatePositionSilently {deltaX:00} {deltaY:00}");
base.UpdatePositionSilently(deltaX, deltaY);

foreach (var child in Children)
child.UpdatePositionSilently(deltaX, deltaY);

Refresh();
}

public void Ungroup()
Expand Down Expand Up @@ -113,7 +118,14 @@ private bool UpdateDimensions()
return false;

var bounds = Children.GetBounds();
Position = new Point(bounds.Left - Padding, bounds.Top - Padding);

var newPosition = new Point(bounds.Left - Padding, bounds.Top - Padding);
if (!Position.Equals(newPosition))
{
Position = newPosition;
TriggerMoving();
}

Size = new Size(bounds.Width + Padding * 2, bounds.Height + Padding * 2);
return true;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Blazor.Diagrams.Core/Models/NodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public virtual void UpdatePositionSilently(double deltaX, double deltaY)

public virtual IShape GetShape() => Shapes.Rectangle(this);

public virtual bool CanAttachTo(ILinkable other) => other is not PortModel && other is not BaseLinkModel;

private void UpdatePortPositions(double deltaX, double deltaY)
{
// Save some JS calls and update ports directly here
Expand All @@ -148,7 +150,10 @@ private void UpdatePortPositions(double deltaX, double deltaY)
}
}

public virtual bool CanAttachTo(ILinkable other) => other is not PortModel && other is not BaseLinkModel;
protected void TriggerMoving()
{
Moving?.Invoke(this);
}

void ILinkable.AddLink(BaseLinkModel link) => _links.Add(link);

Expand Down

0 comments on commit 09c9a8e

Please sign in to comment.