Fixed compile errors in Artemis.UI

This commit is contained in:
Robert committed 2023-03-30 23:13:39 +02:00
1 parent 81e83e59f6
commit d171b947b7
160 files changed
+407 -521

No files matched your search

@@ -18,8 +18,8 @@
<shared:SKColorToStringConverter x:Key="SKColorToStringConverter" />
<shared:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</UserControl.Resources>
<Canvas PointerEnter="OnPointerEnter"
PointerLeave="OnPointerLeave">
<Canvas PointerEntered="OnPointerEnter"
PointerExited="OnPointerLeave">
<Path Name="CablePath"
Stroke="{CompiledBinding CableColor, Converter={StaticResource ColorToSolidColorBrushConverter}}"
StrokeThickness="4"
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Mixins;
@@ -12,22 +13,18 @@ using ReactiveUI;
namespace Artemis.UI.Screens.VisualScripting;
public class CableView : ReactiveUserControl<CableViewModel>
public partial class CableView : ReactiveUserControl<CableViewModel>
{
private const double CABLE_OFFSET = 24 * 4;
private readonly Path _cablePath;
private readonly Border _valueBorder;
public CableView()
{
InitializeComponent();
_cablePath = this.Get<Path>("CablePath");
_valueBorder = this.Get<Border>("ValueBorder");
// Not using bindings here to avoid a warnings
this.WhenActivated(d =>
{
_valueBorder.GetObservable(BoundsProperty).Subscribe(rect => _valueBorder.RenderTransform = new TranslateTransform(rect.Width / 2 * -1, rect.Height / 2 * -1)).DisposeWith(d);
ValueBorder.GetObservable(BoundsProperty).Subscribe(rect => ValueBorder.RenderTransform = new TranslateTransform(rect.Width / 2 * -1, rect.Height / 2 * -1)).DisposeWith(d);
ViewModel.WhenAnyValue(vm => vm.FromPoint).Subscribe(_ => Update(true)).DisposeWith(d);
ViewModel.WhenAnyValue(vm => vm.ToPoint).Subscribe(_ => Update(false)).DisposeWith(d);
@@ -43,21 +40,21 @@ public class CableView : ReactiveUserControl<CableViewModel>
private void Update(bool from)
{
// Workaround for https://github.com/AvaloniaUI/Avalonia/issues/4748
_cablePath.Margin = new Thickness(_cablePath.Margin.Left + 1, _cablePath.Margin.Top + 1, 0, 0);
if (_cablePath.Margin.Left > 2)
_cablePath.Margin = new Thickness(0, 0, 0, 0);
CablePath.Margin = new Thickness(CablePath.Margin.Left + 1, CablePath.Margin.Top + 1, 0, 0);
if (CablePath.Margin.Left > 2)
CablePath.Margin = new Thickness(0, 0, 0, 0);
PathFigure pathFigure = ((PathGeometry) _cablePath.Data).Figures.First();
PathFigure pathFigure = ((PathGeometry) CablePath.Data).Figures.First();
BezierSegment segment = (BezierSegment) pathFigure.Segments!.First();
pathFigure.StartPoint = ViewModel!.FromPoint;
segment.Point1 = new Point(ViewModel.FromPoint.X + CABLE_OFFSET, ViewModel.FromPoint.Y);
segment.Point2 = new Point(ViewModel.ToPoint.X - CABLE_OFFSET, ViewModel.ToPoint.Y);
segment.Point3 = new Point(ViewModel.ToPoint.X, ViewModel.ToPoint.Y);
Canvas.SetLeft(_valueBorder, ViewModel.FromPoint.X + (ViewModel.ToPoint.X - ViewModel.FromPoint.X) / 2);
Canvas.SetTop(_valueBorder, ViewModel.FromPoint.Y + (ViewModel.ToPoint.Y - ViewModel.FromPoint.Y) / 2);
Canvas.SetLeft(ValueBorder, ViewModel.FromPoint.X + (ViewModel.ToPoint.X - ViewModel.FromPoint.X) / 2);
Canvas.SetTop(ValueBorder, ViewModel.FromPoint.Y + (ViewModel.ToPoint.Y - ViewModel.FromPoint.Y) / 2);
_cablePath.InvalidateVisual();
CablePath.InvalidateVisual();
}
private void OnPointerEnter(object? sender, PointerEventArgs e)
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Mixins;
@@ -11,15 +12,13 @@ using ReactiveUI;
namespace Artemis.UI.Screens.VisualScripting;
public class DragCableView : ReactiveUserControl<DragCableViewModel>
public partial class DragCableView : ReactiveUserControl<DragCableViewModel>
{
private const double CABLE_OFFSET = 24 * 4;
private readonly Path _cablePath;
public DragCableView()
{
InitializeComponent();
_cablePath = this.Get<Path>("CablePath");
// Not using bindings here to avoid warnings
this.WhenActivated(d =>
@@ -37,8 +36,11 @@ public class DragCableView : ReactiveUserControl<DragCableViewModel>
private void Update()
{
PathFigure pathFigure = ((PathGeometry) _cablePath.Data).Figures.First();
BezierSegment segment = (BezierSegment) pathFigure.Segments!.First();
PathFigure? pathFigure = ((PathGeometry) CablePath.Data).Figures?.FirstOrDefault();
if (pathFigure?.Segments == null)
return;
BezierSegment segment = (BezierSegment) pathFigure.Segments.First();
pathFigure.StartPoint = ViewModel!.FromPoint;
segment.Point1 = new Point(ViewModel.FromPoint.X + CABLE_OFFSET, ViewModel.FromPoint.Y);
segment.Point2 = new Point(ViewModel.ToPoint.X - CABLE_OFFSET, ViewModel.ToPoint.Y);
@@ -17,15 +17,15 @@
<Setter Property="InnerRightContent">
<Template>
<StackPanel Orientation="Horizontal">
<controls:Button Content="&#xE8BB;"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Classes="AppBarButton"
Command="{Binding $parent[TextBox].Clear}"
IsVisible="{Binding $parent[TextBox].Text, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
<controls:Button Content="&#xE721;"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Classes="AppBarButton"
IsHitTestVisible="False" />
<Button Content="&#xE8BB;"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Classes="AppBarButton"
Command="{Binding $parent[TextBox].Clear}"
IsVisible="{Binding $parent[TextBox].Text, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
<Button Content="&#xE721;"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Classes="AppBarButton"
IsHitTestVisible="False" />
</StackPanel>
</Template>
</Setter>
@@ -1,4 +1,5 @@
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Artemis.Core;
using Avalonia;
@@ -13,7 +14,7 @@ using ReactiveUI;
namespace Artemis.UI.Screens.VisualScripting;
public class NodePickerView : ReactiveUserControl<NodePickerViewModel>
public partial class NodePickerView : ReactiveUserControl<NodePickerViewModel>
{
public NodePickerView()
{
@@ -21,7 +22,7 @@ public class NodePickerView : ReactiveUserControl<NodePickerViewModel>
this.WhenActivated(d =>
{
ViewModel?.WhenAnyValue(vm => vm.IsVisible).Where(visible => visible == false).Subscribe(_ => this.FindLogicalAncestorOfType<ZoomBorder>()?.ContextFlyout?.Hide()).DisposeWith(d);
this.Get<TextBox>("SearchBox").SelectAll();
SearchBox.SelectAll();
});
}
@@ -19,28 +19,19 @@ using ReactiveUI;
namespace Artemis.UI.Screens.VisualScripting;
public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
public partial class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
{
private readonly Grid _grid;
private readonly ItemsControl _nodesContainer;
private readonly SelectionRectangle _selectionRectangle;
private readonly ZoomBorder _zoomBorder;
public NodeScriptView()
{
InitializeComponent();
_grid = this.Find<Grid>("ContainerGrid");
_zoomBorder = this.Find<ZoomBorder>("ZoomBorder");
_nodesContainer = this.Find<ItemsControl>("NodesContainer");
_selectionRectangle = this.Find<SelectionRectangle>("SelectionRectangle");
_zoomBorder.PropertyChanged += ZoomBorderOnPropertyChanged;
ZoomBorder.PropertyChanged += ZoomBorderOnPropertyChanged;
UpdateZoomBorderBackground();
_zoomBorder.AddHandler(PointerReleasedEvent, CanvasOnPointerReleased, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
_zoomBorder.AddHandler(PointerWheelChangedEvent, ZoomOnPointerWheelChanged, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
_zoomBorder.AddHandler(PointerMovedEvent, ZoomOnPointerMoved, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
ZoomBorder.AddHandler(PointerReleasedEvent, CanvasOnPointerReleased, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
ZoomBorder.AddHandler(PointerWheelChangedEvent, ZoomOnPointerWheelChanged, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
ZoomBorder.AddHandler(PointerMovedEvent, ZoomOnPointerMoved, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
this.WhenActivated(d =>
{
ViewModel!.AutoFitRequested += ViewModelOnAutoFitRequested;
@@ -65,22 +56,22 @@ public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
private void ZoomOnPointerWheelChanged(object? sender, PointerWheelEventArgs e)
{
// If scroll events aren't handled here the ZoomBorder does some random panning when at the zoom limit
if (e.Delta.Y > 0 && _zoomBorder.ZoomX >= 1)
if (e.Delta.Y > 0 && ZoomBorder.ZoomX >= 1)
e.Handled = true;
}
private void ZoomOnPointerMoved(object? sender, PointerEventArgs e)
{
if (ViewModel != null)
ViewModel.PastePosition = e.GetPosition(_grid);
ViewModel.PastePosition = e.GetPosition(ContainerGrid);
}
private void ShowPickerAt(Point point)
{
if (ViewModel == null)
return;
ViewModel.NodePickerViewModel.Position = point;
_zoomBorder?.ContextFlyout?.ShowAt(_zoomBorder, true);
ZoomBorder?.ContextFlyout?.ShowAt(ZoomBorder);
}
private void AutoFitIfPreview()
@@ -91,7 +82,7 @@ public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
private void BoundsPropertyChanged(AvaloniaPropertyChangedEventArgs<Rect> obj)
{
if (_nodesContainer.ItemContainerGenerator.Containers.Select(c => c.ContainerControl).Contains(obj.Sender))
if (NodesContainer.GetRealizedContainers().Contains(obj.Sender))
AutoFitIfPreview();
}
@@ -99,18 +90,19 @@ public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
{
// If the flyout handled the click, update the position of the node picker
if (e.Handled && ViewModel != null)
ViewModel.NodePickerViewModel.Position = e.GetPosition(_grid);
ViewModel.NodePickerViewModel.Position = e.GetPosition(ContainerGrid);
}
private void AutoFit(bool skipTransitions)
{
if (!_nodesContainer.ItemContainerGenerator.Containers.Any())
List<Control> containers = NodesContainer.GetRealizedContainers().ToList();
if (!containers.Any())
return;
double left = _nodesContainer.ItemContainerGenerator.Containers.Select(c => c.ContainerControl.Bounds.Left).Min();
double top = _nodesContainer.ItemContainerGenerator.Containers.Select(c => c.ContainerControl.Bounds.Top).Min();
double bottom = _nodesContainer.ItemContainerGenerator.Containers.Select(c => c.ContainerControl.Bounds.Bottom).Max();
double right = _nodesContainer.ItemContainerGenerator.Containers.Select(c => c.ContainerControl.Bounds.Right).Max();
double left = containers.Select(c => c.Bounds.Left).Min();
double top = containers.Select(c => c.Bounds.Top).Min();
double bottom = containers.Select(c => c.Bounds.Bottom).Max();
double right = containers.Select(c => c.Bounds.Right).Max();
// Add a 10 pixel margin around the rect
Rect scriptRect = new(new Point(left - 10, top - 10), new Point(right + 10, bottom + 10));
@@ -119,8 +111,8 @@ public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
double scale = Math.Min(1, Math.Min(Bounds.Width / scriptRect.Width, Bounds.Height / scriptRect.Height));
// Pan and zoom to make the script fit
_zoomBorder.Zoom(scale, 0, 0, skipTransitions);
_zoomBorder.Pan(Bounds.Center.X - scriptRect.Center.X * scale, Bounds.Center.Y - scriptRect.Center.Y * scale, skipTransitions);
ZoomBorder.Zoom(scale, 0, 0, skipTransitions);
ZoomBorder.Pan(Bounds.Center.X - scriptRect.Center.X * scale, Bounds.Center.Y - scriptRect.Center.Y * scale, skipTransitions);
}
private void ViewModelOnAutoFitRequested(object? sender, EventArgs e)
@@ -130,14 +122,14 @@ public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
private void ZoomBorderOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property.Name == nameof(_zoomBorder.Background))
if (e.Property.Name == nameof(ZoomBorder.Background))
UpdateZoomBorderBackground();
}
private void UpdateZoomBorderBackground()
{
if (_zoomBorder.Background is VisualBrush visualBrush)
visualBrush.DestinationRect = new RelativeRect(_zoomBorder.OffsetX * -1, _zoomBorder.OffsetY * -1, 20, 20, RelativeUnit.Absolute);
if (ZoomBorder.Background is VisualBrush visualBrush)
visualBrush.DestinationRect = new RelativeRect(ZoomBorder.OffsetX * -1, ZoomBorder.OffsetY * -1, 20, 20, RelativeUnit.Absolute);
}
private void InitializeComponent()
@@ -148,14 +140,14 @@ public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
private void ZoomBorder_OnZoomChanged(object sender, ZoomChangedEventArgs e)
{
if (ViewModel != null)
ViewModel.PanMatrix = _zoomBorder.Matrix;
ViewModel.PanMatrix = ZoomBorder.Matrix;
UpdateZoomBorderBackground();
}
private void SelectionRectangle_OnSelectionUpdated(object? sender, SelectionRectangleEventArgs e)
{
List<ItemContainerInfo> itemContainerInfos = _nodesContainer.ItemContainerGenerator.Containers.Where(c => c.ContainerControl.Bounds.Intersects(e.Rectangle)).ToList();
List<NodeViewModel> nodes = itemContainerInfos.Where(c => c.Item is NodeViewModel).Select(c => (NodeViewModel) c.Item).ToList();
List<Control> itemContainerInfos = NodesContainer.GetRealizedContainers().Where(c => c.Bounds.Intersects(e.Rectangle)).ToList();
List<NodeViewModel> nodes = itemContainerInfos.Where(c => c.DataContext is NodeViewModel).Select(c => (NodeViewModel) c.DataContext!).ToList();
ViewModel?.UpdateNodeSelection(nodes, e.KeyModifiers.HasFlag(KeyModifiers.Shift), e.KeyModifiers.HasFlag(KeyModifiers.Control));
}
@@ -166,7 +158,7 @@ public class NodeScriptView : ReactiveUserControl<NodeScriptViewModel>
private void ZoomBorder_OnPointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (!_selectionRectangle.IsSelecting && e.InitialPressMouseButton == MouseButton.Left)
if (!SelectionRectangle.IsSelecting && e.InitialPressMouseButton == MouseButton.Left)
ViewModel?.ClearNodeSelection();
}
}
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
@@ -17,7 +18,6 @@ using Artemis.UI.Shared;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.Services.NodeEditor.Commands;
using Avalonia;
using Avalonia.Controls.Mixins;
using Avalonia.Input;
using DynamicData;
using DynamicData.Binding;
@@ -1,4 +1,4 @@
<Window xmlns="https://github.com/avaloniaui"
<windowing:AppWindow xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -6,6 +6,7 @@
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
xmlns:windowing="clr-namespace:FluentAvalonia.UI.Windowing;assembly=FluentAvalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.VisualScripting.NodeScriptWindowView"
x:DataType="visualScripting:NodeScriptWindowViewModel"
@@ -181,4 +182,4 @@
</Grid>
</Window>
</windowing:AppWindow>
@@ -4,7 +4,7 @@ using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.VisualScripting;
public class NodeScriptWindowView : ReactiveAppWindow<NodeScriptWindowViewModel>
public partial class NodeScriptWindowView : ReactiveAppWindow<NodeScriptWindowViewModel>
{
public NodeScriptWindowView()
{
@@ -9,7 +9,7 @@ using Avalonia.VisualTree;
namespace Artemis.UI.Screens.VisualScripting;
public class NodeView : ReactiveUserControl<NodeViewModel>
public partial class NodeView : ReactiveUserControl<NodeViewModel>
{
private bool _dragging;
@@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.Core.Events;
@@ -12,7 +13,6 @@ using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.Services.NodeEditor.Commands;
using Avalonia;
using Avalonia.Controls.Mixins;
using Avalonia.Layout;
using DynamicData;
using DynamicData.Binding;
@@ -3,7 +3,7 @@ using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.VisualScripting.Pins;
public class InputPinCollectionView : ReactiveUserControl<PinCollectionViewModel>
public partial class InputPinCollectionView : ReactiveUserControl<PinCollectionViewModel>
{
public InputPinCollectionView()
{
@@ -5,7 +5,7 @@ using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.VisualScripting.Pins;
public class InputPinView : PinView
public partial class InputPinView : PinView
{
public InputPinView()
{
@@ -3,7 +3,7 @@ using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.VisualScripting.Pins;
public class OutputPinCollectionView : ReactiveUserControl<PinCollectionViewModel>
public partial class OutputPinCollectionView : ReactiveUserControl<PinCollectionViewModel>
{
public OutputPinCollectionView()
{
@@ -5,7 +5,7 @@ using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.VisualScripting.Pins;
public class OutputPinView : PinView
public partial class OutputPinView : PinView
{
public OutputPinView()
{
@@ -2,13 +2,13 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.Core.Events;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.Services.NodeEditor.Commands;
using Avalonia.Controls.Mixins;
using DynamicData;
using ReactiveUI;
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.Core.Events;
@@ -10,7 +11,6 @@ using Artemis.UI.Shared.Extensions;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.Services.NodeEditor.Commands;
using Avalonia;
using Avalonia.Controls.Mixins;
using Avalonia.Media;
using DynamicData;
using ReactiveUI;