Skip to content

Commit

Permalink
- Fixed the adaptive node layout calculation error
Browse files Browse the repository at this point in the history
- Added node centerline alignment
  • Loading branch information
MakesYT committed Feb 8, 2024
1 parent 32741c1 commit 3fec262
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
41 changes: 32 additions & 9 deletions NodifyM.Avalonia/Controls/NodifyEditor.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,20 @@ protected override void OnLoaded(RoutedEventArgs e)
base.OnLoaded(e);
var T = 0.0d;
var L = 0.0d;
var B = this.Bounds.Height;
var R = this.Bounds.Width;
var B = 0d;
var R = 0d;
var childOfType = this.GetChildOfType<Canvas>("NodeItemsPresenter");
foreach (var logicalChild in childOfType.GetVisualChildren())
{
var logicalChildLogicalChild = ((BaseNode)logicalChild.GetVisualChildren().First());
var location = logicalChildLogicalChild.Location;
if (location.Y< L)
if (location.Y< T)
{
L = location.Y;
T = location.Y;
}
if (location.X < T)
if (location.X < L)
{
T = location.X;
L = location.X;
}
if (location.Y+ logicalChildLogicalChild.Bounds.Height> B)
{
Expand Down Expand Up @@ -559,7 +559,30 @@ public Point TryAlignNode(BaseNode control,Point point)
: new AlignmentLineViewModel(new Point(x, control.Location.Y+movingNodeHeight),
new Point(x, nodeLocationY)));
}

//竖中
var intervalX5 = Math.Abs((nodeLocationX + nodeWidth/2) - (x + movingNodeWidth/2));
if (intervalX5 <= nowIntervalX)
{
x = (nodeLocationX + nodeWidth/2)-movingNodeWidth/2;
nowIntervalX = intervalX5;
AlignmentLine.Add(y <= nodeLocationY
? new AlignmentLineViewModel(new Point(x+movingNodeWidth/2, control.Location.Y),
new Point(x+movingNodeWidth/2, nodeLocationY+nodeHeight))
: new AlignmentLineViewModel(new Point(x+movingNodeWidth/2, control.Location.Y+movingNodeHeight),
new Point(x+movingNodeWidth/2, nodeLocationY)));
}
// 横中
var intervalY5 = Math.Abs(nodeLocationY + nodeHeight/2 - y-movingNodeHeight/2);
if (intervalY5 <= nowIntervalY)
{

y = nodeLocationY + nodeHeight/2-movingNodeHeight/2;
nowIntervalY = intervalY5;
AlignmentLine.Add(x <= nodeLocationX
? new AlignmentLineViewModel(new Point(nodeLocationX + nodeWidth, y+movingNodeHeight/2 ), new Point(control.Location.X, y +movingNodeHeight/2))
: new AlignmentLineViewModel(new Point(nodeLocationX, y+movingNodeHeight/2 ),
new Point(control.Location.X + movingNodeWidth, y+movingNodeHeight/2 )));
}

}

Expand All @@ -571,7 +594,7 @@ public Point TryAlignNode(BaseNode control,Point point)
if (alignmentLineViewModel.Start.X.Equals(alignmentLineViewModel.End.X))
{
//竖向
if (!alignmentLineViewModel.Start.X.Equals(x)&&!alignmentLineViewModel.Start.X.Equals(x+movingNodeWidth))
if (!alignmentLineViewModel.Start.X.Equals(x)&&!alignmentLineViewModel.Start.X.Equals(x+movingNodeWidth)&&!alignmentLineViewModel.Start.X.Equals(x+movingNodeWidth/2))
{
AlignmentLine.RemoveAt(index);
}
Expand All @@ -580,7 +603,7 @@ public Point TryAlignNode(BaseNode control,Point point)
if (alignmentLineViewModel.Start.Y.Equals(alignmentLineViewModel.End.Y))
{
//横向
if (!alignmentLineViewModel.Start.Y.Equals(y)&&!alignmentLineViewModel.Start.Y.Equals(y+movingNodeHeight))
if (!alignmentLineViewModel.Start.Y.Equals(y)&&!alignmentLineViewModel.Start.Y.Equals(y+movingNodeHeight)&&!alignmentLineViewModel.Start.Y.Equals(y+movingNodeHeight/2))
{
AlignmentLine.RemoveAt(index);
}
Expand Down
2 changes: 1 addition & 1 deletion NodifyM.Avalonia/NodifyM.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/MakesYT/NodifyM.Avalonia</PackageProjectUrl>
<LangVersion>10</LangVersion>
<Version>1.0.11</Version>
<Version>1.0.12</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ This project is a refactoring of [Nodify](https://github.com/miroiu/nodify) on t
#### You can git clone the project and run `NodifyM.Avalonia.Example`

## Changelog
### 1.0.12
- Fixed the adaptive node layout calculation error
- Added node centerline alignment
### 1.0.11
- Added automatic adaptation to display all Nodes when NodifyEditor is initialized
- Optimize child node search
Expand Down

0 comments on commit 3fec262

Please sign in to comment.