Skip to content

Commit

Permalink
Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Apr 3, 2024
1 parent 3fec262 commit 7b738e2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions NodifyM.Avalonia.Example/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<StackPanel ZIndex="1">
<Button Content="Switch Theme" Command="{Binding ChangeThemeCommand}"></Button>
<Button ZIndex="1" Content="new" Click="Button_OnClick"></Button>
<TextBlock Text="{Binding #Editor.SelectedItem}"></TextBlock>
</StackPanel>

<controls:NodifyEditor x:Name="Editor"
Expand Down
16 changes: 3 additions & 13 deletions NodifyM.Avalonia/Controls/BaseNode.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,9 @@ private void NodifyAutoPanningEvent(object sender, NodifyAutoPanningEventArgs e)
private void OnPointerPressed(object sender, PointerPressedEventArgs e)
{
e.GetCurrentPoint(this).Pointer.Capture(this);
var visualParent = this.GetVisualParent();
var parent = visualParent.GetVisualParent().GetVisualChildren();
foreach (var visual in parent)
{
visual.ZIndex = 0;
var first = visual.GetVisualChildren().First();
if (first is BaseNode baseNode)
{
baseNode.IsSelected = false;
}
}
visualParent.ZIndex = 1;
this.IsSelected = true;


_editor.SelectItem(this);
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
// 启动拖动
isDragging = true;
Expand Down
3 changes: 3 additions & 0 deletions NodifyM.Avalonia/Controls/Connector.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using NodifyM.Avalonia.Events;
using NodifyM.Avalonia.Helpers;
using NodifyM.Avalonia.ViewModelBase;
Expand Down Expand Up @@ -203,6 +204,8 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
}
else
{
Editor.SelectItem(this.GetParentOfType<BaseNode>());

UpdateAnchor();
OnConnectorDragStarted();
}
Expand Down
18 changes: 17 additions & 1 deletion NodifyM.Avalonia/Controls/NodifyEditor.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,22 @@ public NodifyEditor()
AddHandler(BaseNode.LocationChangedEvent,new NodeLocationEventHandler( OnNodeLocationChanged));
AddHandler(BaseConnection.DisconnectEvent, new ConnectionEventHandler(OnRemoveConnection));
}

public void SelectItem(BaseNode node)
{
var visual = this.GetChildOfType<Canvas>("NodeItemsPresenter").Children;
foreach (var visualChild in visual)
{
visualChild.ZIndex = 0;
if (visualChild.GetChildOfType<BaseNode>() is BaseNode n)
{
n.IsSelected = false;
}

}
node.IsSelected = true;
node.GetVisualParent().ZIndex = 1;
SelectedItem = node.DataContext;
}


protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Expand Down Expand Up @@ -281,6 +296,7 @@ private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
n.IsSelected = false;
}
}
SelectedItem=null;
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
isDragging = true;
lastMousePosition = e.GetPosition(this);
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.12</Version>
<Version>1.0.13</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.13
- Fixed SelectedNode Property
- Added the ability to select and drag the Node corresponding to the Connector
### 1.0.12
- Fixed the adaptive node layout calculation error
- Added node centerline alignment
Expand Down

0 comments on commit 7b738e2

Please sign in to comment.