Skip to content

Commit

Permalink
- Added automatic adaptation to display all Nodes when NodifyEditor i…
Browse files Browse the repository at this point in the history
…s initialized

- Optimize child node search
  • Loading branch information
MakesYT committed Feb 6, 2024
1 parent 585e2d7 commit 7c586b0
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
3 changes: 2 additions & 1 deletion NodifyM.Avalonia.Example/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public MainWindowViewModel()
Nodes =new(){
new NodeViewModelBase()
{
Location = new Point(400, 100),
Location = new Point(400, 2000),
Title = "Node 1",
Input = new ObservableCollection<ConnectorViewModelBase>
{
Expand All @@ -49,6 +49,7 @@ public MainWindowViewModel()
new NodeViewModelBase()
{
Title = "Node 2",
Location = new Point(-100,-100),
Input = new ObservableCollection<ConnectorViewModelBase>
{
new ConnectorViewModelBase()
Expand Down
52 changes: 51 additions & 1 deletion NodifyM.Avalonia/Controls/NodifyEditor.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,60 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
RenderTransform = renderTransform;
AutoPanningTimer=new DispatcherTimer(TimeSpan.FromMilliseconds(10), DispatcherPriority.Normal,HandleAutoPanning);
AutoPanningTimer.Stop();
ViewTranslateTransform = new TranslateTransform();

AlignmentLine = new AvaloniaList<object>();

}

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 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)
{
L = location.Y;
}
if (location.X < T)
{
T = location.X;
}
if (location.Y+ logicalChildLogicalChild.Bounds.Height> B)
{
B = location.Y+ logicalChildLogicalChild.Bounds.Height;
}
if (location.X + logicalChildLogicalChild.Bounds.Width > R)
{
R = location.X + logicalChildLogicalChild.Bounds.Width;
}

}
ViewTranslateTransform = new TranslateTransform(-L,-T);
OffsetY = -T;
OffsetX = -L;
if (1/(Math.Abs(T - B) / _initHeight)<ScaleTransform.ScaleY)
{
ScaleTransform.ScaleY = 1/(Math.Abs(T - B) / _initHeight);
ScaleTransform.ScaleX = 1/(Math.Abs(T - B) / _initHeight);
}
if (1/(Math.Abs(L - R) / _initWeight)<ScaleTransform.ScaleY)
{
ScaleTransform.ScaleY = 1/(Math.Abs(L - R) / _initWeight);
ScaleTransform.ScaleX = 1/(Math.Abs(L - R) / _initWeight);
}
Zoom = ScaleTransform.ScaleY;
_nowScale = Zoom;
Width = _initWeight / Zoom;
Height = _initHeight / Zoom;

}


/// <summary>
Expand Down
17 changes: 9 additions & 8 deletions NodifyM.Avalonia/Helpers/DependencyObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia;
using System.Diagnostics;
using Avalonia;
using Avalonia.Controls;
using Avalonia.VisualTree;

Expand Down Expand Up @@ -36,13 +37,13 @@ internal static class DependencyObjectExtensions
public static T? GetChildOfType<T>(this Control control, string? name = null)
where T : Control
{
var stack = new Stack<Control>();
stack.Push(control);
var queue = new Queue<Control>();
queue.Enqueue(control);

while (stack.Count > 0)
while (queue.Count > 0)
{
var currentControl = stack.Pop();
var currentControl = queue.Dequeue();

if (string.IsNullOrEmpty(name) && currentControl is T targetControl)
{
return targetControl;
Expand All @@ -60,8 +61,8 @@ internal static class DependencyObjectExtensions
return targetChild;
}
}
stack.Push(childControl);

queue.Enqueue(childControl);
}
}
}
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.11
- Added automatic adaptation to display all Nodes when NodifyEditor is initialized
- Optimize child node search
### 1.0.10
- Fixed Node Header/Input/OutputTemplate allow use IDataTemplate
- Added Avalonia.Diagnostics Condition
Expand Down

0 comments on commit 7c586b0

Please sign in to comment.