Skip to content

Commit

Permalink
Added the ability to temporarily unalign nodes automatically while ho…
Browse files Browse the repository at this point in the history
…lding Shift

Added the ability to display text on Connection
  • Loading branch information
MakesYT committed Jan 30, 2024
1 parent 70d0ef1 commit 1573788
Show file tree
Hide file tree
Showing 11 changed files with 544 additions and 12 deletions.
2 changes: 2 additions & 0 deletions NodifyM.Avalonia.Example/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<DataTemplate DataType="{x:Type viewModelBase:ConnectionViewModelBase}">
<Grid>
<controls:Connection
Text="{Binding Text}"
TextPoint="50%,50%"
SplitCommand="{Binding SplitConnectionCommand}"
DisconnectCommand="{Binding DisconnectConnectionCommand}"
Direction="{Binding .,Converter={StaticResource FlowToDirectionConverter}}"
Expand Down
2 changes: 1 addition & 1 deletion NodifyM.Avalonia.Example/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MainWindowViewModel()
Title = "B 1",
Flow = ConnectorViewModelBase.ConnectorFlow.Output
};
Connections.Add(new ConnectionViewModelBase(this,output1,knot1.Connector));
Connections.Add(new ConnectionViewModelBase(this,output1,knot1.Connector,"Test"));
Connections.Add(new ConnectionViewModelBase(this,knot1.Connector,input1));
Nodes =new(){
new NodeViewModelBase()
Expand Down
22 changes: 16 additions & 6 deletions NodifyM.Avalonia/Controls/BaseConnection.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Globalization;
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls.Shapes;
Expand Down Expand Up @@ -101,7 +102,7 @@ public enum ArrowHeadShape
Rectangle
}

public class BaseConnection : Shape
public class BaseConnection : BaseConnectionShape
{
#region Dependency Properties

Expand Down Expand Up @@ -293,24 +294,33 @@ public event ConnectionEventHandler Split

public BaseConnection()
{
Shape.AffectsGeometry<BaseConnection>(SourceProperty, TargetProperty);
BaseConnectionShape.AffectsGeometry<BaseConnection>(SourceProperty, TargetProperty,TextProperty);
}
/// <summary>
/// Gets a vector that has its coordinates set to 0.
/// </summary>
protected static readonly Vector ZeroVector = new Vector(0d, 0d);

private StreamGeometry _geometry = new StreamGeometry
protected override Geometry? CreateDefiningTextGeometry()
{
};

if (Text is null)
{
return null;
}
(Vector sourceOffset, Vector targetOffset) = GetOffset();
Point source = Source + sourceOffset;
Point target = Target + targetOffset;
var formattedText = new FormattedText(Text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("Inter"), TextSize, Brushes.Black);
return (formattedText.BuildGeometry(new Point((source.X + target.X)*TextPoint.Point.X, (source.Y + target.Y)*TextPoint.Point.Y)));
}

protected override Geometry CreateDefiningGeometry()
{
{
_geometry = new StreamGeometry();
var _geometry = new StreamGeometry();
using (StreamGeometryContext context = _geometry.Open())
{

context.SetFillRule( FillRule.EvenOdd);
(Vector sourceOffset, Vector targetOffset) = GetOffset();
Point source = Source + sourceOffset;
Expand Down
12 changes: 12 additions & 0 deletions NodifyM.Avalonia/Controls/BaseConnectionShape.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:NodifyM.Avalonia.Controls">
<Design.PreviewWith>
<controls:BaseConnectionShape />
</Design.PreviewWith>

<Style Selector="controls|BaseConnectionShape">
<!-- Set Defaults -->

</Style>
</Styles>
Loading

0 comments on commit 1573788

Please sign in to comment.