| 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
using System; using System.ComponentModel; 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) { var horizontal = Math.Max(Math.Abs(scene.Bounds.Left), Math.Abs(scene.Bounds.Right)); var vertical = Math.Max(Math.Abs(scene.Bounds.Top), Math.Abs(scene.Bounds.Bottom)); editor.FitToScreen(new Avalonia.Rect(-horizontal, -vertical, horizontal * 2, vertical * 2)); } } }