Skip to content

Commit c3a61c6

Browse files
committed
fix update connectors position
1 parent cfa08f2 commit c3a61c6

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ private void SetupBinding()
8080
this.OneWayBind(this.ViewModel, x => x.Output, x => x.Output.ViewModel).DisposeWith(disposable);
8181

8282
this.OneWayBind(this.ViewModel, x => x.Transitions, x => x.ItemsControlTransitions.ItemsSource).DisposeWith(disposable);
83-
83+
84+
this.WhenAnyValue(v => v.NodeHeaderElement.ActualWidth).BindTo(this, v => v.ViewModel.HeaderWidth).DisposeWith(disposable);
85+
8486
});
8587
}
8688
#endregion Setup Binding

SimpleStateMachineNodeEditor/ViewModel/Connector/ViewModelConnector.cs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public partial class ViewModelConnector : ReactiveObject
3030
[Reactive] public ViewModelNodesCanvas NodesCanvas { get; set; }
3131
[Reactive] public bool Selected { get; set; }
3232

33-
private IDisposable subscriptionOnNodeWidthChange;
3433
public ViewModelConnector(ViewModelNodesCanvas nodesCanvas, ViewModelNode viewModelNode, string name, Point myPoint)
3534
{
3635
Node = viewModelNode;
@@ -48,29 +47,17 @@ private void SetupSubscriptions()
4847

4948
if (this.Name!="Input")
5049
{
51-
this.WhenAnyValue(x => x.Node.IsCollapse).Subscribe(value => UpdateSubscriptionForPosition(value));
50+
this.WhenAnyValue(x => x.Node.HeaderWidth).Buffer(2, 1).Subscribe(x => UpdatePositionOnWidthChange(x[1] - x[0]));
5251
if (this.Name != "Output")
5352
{
54-
this.WhenAnyValue(x => x.Node.Transitions.Count).Subscribe(x => UpdatePositionOnTransitionCountChange());
55-
53+
this.WhenAnyValue(x => x.Node.Transitions.Count).Subscribe(x => UpdatePositionOnTransitionCountChange());
5654
}
5755

5856
}
5957

6058
this.WhenAnyValue(x => x.Node.Point1).Buffer(2, 1).Subscribe(value => PositionConnectPoint = PositionConnectPoint.Addition(value[1].Subtraction(value[0])));
6159
}
62-
private void UpdateSubscriptionForPosition(bool nodeIsCollapse)
63-
{
64-
if (!nodeIsCollapse)
65-
{
66-
subscriptionOnNodeWidthChange = this.WhenAnyValue(x => x.Node.Size.Width).Buffer(2, 1).Where(x => (x[0]>= 80 && x[1] >= 80))
67-
.Subscribe(x => UpdatePositionOnWidthChange(x[1] - x[0]));
68-
}
69-
else
70-
{
71-
subscriptionOnNodeWidthChange?.Dispose();
72-
}
73-
}
60+
7461
private void UpdatePositionOnTransitionCountChange()
7562
{
7663
if (!string.IsNullOrEmpty(Name))
@@ -81,13 +68,7 @@ private void UpdatePositionOnTransitionCountChange()
8168
}
8269
private void UpdatePositionOnWidthChange(double value)
8370
{
84-
if(!Node.AfterCollapse)
85-
this.PositionConnectPoint = this.PositionConnectPoint.Addition(value, 0);
86-
87-
if ((Node.AfterCollapse)&&(string.IsNullOrEmpty(this.Name)))
88-
{
89-
Node.AfterCollapse = false;
90-
}
71+
this.PositionConnectPoint = this.PositionConnectPoint.Addition(value, 0);
9172
}
9273
private void UpdateResources()
9374
{

SimpleStateMachineNodeEditor/ViewModel/Node/ViewModelNode.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ public partial class ViewModelNode : ReactiveValidationObject<ViewModelNode>
1919
[Reactive] public Point Point1 { get; set; }
2020
[Reactive] public Point Point2 { get; set; }
2121
[Reactive] public Size Size { get; set; }
22-
//[Reactive] public double WidthBeforeCollapse { get; set; }
23-
[Reactive] public bool AfterCollapse { get; set; }
2422
[Reactive] public string Name { get; set; }
2523
[Reactive] public bool NameEnable { get; set; } = true;
2624
[Reactive] public bool Selected { get; set; }
@@ -35,6 +33,8 @@ public partial class ViewModelNode : ReactiveValidationObject<ViewModelNode>
3533
[Reactive] public ViewModelNodesCanvas NodesCanvas { get; set; }
3634
[Reactive] public int IndexStartSelectConnectors { get; set; } = 0;
3735

36+
[Reactive] public double HeaderWidth { get; set; } = 80;
37+
3838
public IObservableCollection<ViewModelConnector> Transitions { get; set; } = new ObservableCollectionExtended<ViewModelConnector>();
3939
public int Zindex { get; private set; }
4040

@@ -105,8 +105,6 @@ private void Collapse(bool value)
105105
}
106106
else
107107
{
108-
AfterCollapse = true;
109-
//WidthBeforeCollapse = Size.Width;
110108
TransitionsVisible = null;
111109
Output.Visible = true;
112110
UnSelectedAllConnectors();

0 commit comments

Comments
 (0)