| Name | Message | Date |
|---|---|---|
| 📄 GraphConnection.cs | 5 days ago | |
| 📄 MainWindow.axaml | 5 days ago | |
| 📄 MainWindow.axaml.cs | 5 days ago |
📄
ui/src/Views/MainWindow.axaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System; using System.ComponentModel; using System.Linq; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Threading; using Cfa.Ui.ViewModels; using Nodify; namespace Cfa.Ui.Views; public sealed partial class MainWindow : Window { private MainViewModel? model; public MainWindow() { AvaloniaXamlLoader.Load(this); DataContextChanged += OnDataContextChanged; Closed += (_, _) => { if (model is not null) { model.PropertyChanged -= OnModelChanged; } }; } private void OnDataContextChanged(object? sender, EventArgs args) { if (model is not null) { model.PropertyChanged -= OnModelChanged; } model = DataContext as MainViewModel; if (model is not null) { model.PropertyChanged += OnModelChanged; } } private void OnModelChanged(object? sender, PropertyChangedEventArgs args) { if (args.PropertyName == nameof(MainViewModel.Scene)) { Dispatcher.UIThread.Post(() => FitGraph(this, new RoutedEventArgs()), DispatcherPriority.Loaded); } } private void FitGraph(object? sender, RoutedEventArgs args) { var editor = this.FindControl<NodifyEditor>("Editor")!; editor.UpdateLayout(); if (model?.Scene is { } scene) { if (scene.Nodes.Count > 0 && editor.Bounds.Width > 0 && editor.Bounds.Height > 0) { var bounds = scene.Nodes.Select(node => node.Bounds).Aggregate((first, next) => first.Union(next)); var zoom = Math.Min( editor.MaxViewportZoom, Math.Min(editor.Bounds.Width / bounds.Width, editor.Bounds.Height / bounds.Height) ); editor.MinViewportZoom = Math.Min(editor.MinViewportZoom, zoom); editor.ViewportZoom = zoom; editor.ViewportLocation = bounds.Center - new Point( editor.Bounds.Width / editor.ViewportZoom / 2, editor.Bounds.Height / editor.ViewportZoom / 2 ); } } } }