From f249f80d19548dd8c5b9d0defa00efb6b0eba96d Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 5 Jun 2023 23:39:57 +0200 Subject: [PATCH] Upgrade Avalonia to 11 rc1 --- src/Artemis.UI.Linux/Artemis.UI.Linux.csproj | 8 ++-- src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj | 8 ++-- .../Artemis.UI.Shared.csproj | 12 +++--- .../Controls/DraggableNumberBox.axaml.cs | 8 ++-- .../Controls/HotkeyBox.axaml.cs | 5 ++- src/Artemis.UI.Shared/ReactiveAppWindow.cs | 2 +- src/Artemis.UI.Shared/Utilities.cs | 19 +-------- .../Artemis.UI.Windows.csproj | 10 ++--- src/Artemis.UI/Artemis.UI.csproj | 18 ++++---- .../Behaviors/SimpleContextDragBehavior.cs | 6 ++- .../StringPropertyInputView.axaml.cs | 3 +- .../Panels/MenuBar/MenuBarView.axaml | 2 +- .../SurfaceEditor/SurfaceEditorView.axaml | 8 ++-- .../SurfaceEditor/SurfaceEditorView.axaml.cs | 3 +- .../Screens/VisualScripting/Pins/PinView.cs | 41 +++++-------------- .../Artemis.VisualScripting.csproj | 6 +-- 16 files changed, 64 insertions(+), 95 deletions(-) diff --git a/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj b/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj index 9607a10d8..21c5abd88 100644 --- a/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj +++ b/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj @@ -16,11 +16,11 @@ - - + + - - + + diff --git a/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj b/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj index e674a2ad6..9e2fc0938 100644 --- a/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj +++ b/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj @@ -15,11 +15,11 @@ - - + + - - + + diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 0c4439627..c0c66255d 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -10,14 +10,14 @@ - + - - - + + + - - + + diff --git a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs index 1b3124421..fd3352add 100644 --- a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs +++ b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Avalonia; using Avalonia.Controls; using Avalonia.Data; @@ -68,7 +69,7 @@ public partial class DraggableNumberBox : UserControl public DraggableNumberBox() { InitializeComponent(); - + PointerPressed += OnPointerPressed; PointerMoved += OnPointerMoved; PointerReleased += OnPointerReleased; @@ -186,8 +187,9 @@ public partial class DraggableNumberBox : UserControl private void HandleKeyUp(object? sender, KeyEventArgs e) { + IInputElement? toFocus = this.GetLogicalAncestors().OfType().LastOrDefault(); if (e.Key == Key.Enter || e.Key == Key.Escape) - FocusManager.Instance?.Focus(Parent as IInputElement); + toFocus?.Focus(); } private void OnPointerPressed(object? sender, PointerPressedEventArgs e) @@ -215,7 +217,7 @@ public partial class DraggableNumberBox : UserControl if (!_moved) { // Let our parent take focus, it would make more sense to take focus ourselves but that hides the collider - FocusManager.Instance?.Focus(Parent as IInputElement); + (Parent as IInputElement)?.Focus(); _moved = true; e.Pointer.Capture(this); DragStarted?.Invoke(this, EventArgs.Empty); diff --git a/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs b/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs index 0448f9746..d5d02c63e 100644 --- a/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs +++ b/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs @@ -9,6 +9,7 @@ using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Threading; +using Avalonia.VisualTree; using DryIoc; using FluentAvalonia.Core; using Humanizer; @@ -78,7 +79,7 @@ public partial class HotkeyBox : UserControl private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e) { if (e.Modifiers == KeyboardModifierKey.None) - Dispatcher.UIThread.Post(() => FocusManager.Instance?.Focus(null)); + Dispatcher.UIThread.Post(() => this.FindAncestorOfType()?.Focus()); } private void UpdateDisplayTextBox() @@ -96,7 +97,7 @@ public partial class HotkeyBox : UserControl private void Button_OnClick(object? sender, RoutedEventArgs e) { Hotkey = null; - FocusManager.Instance?.Focus(null); + this.FindAncestorOfType()?.Focus(); UpdateDisplayTextBox(); } diff --git a/src/Artemis.UI.Shared/ReactiveAppWindow.cs b/src/Artemis.UI.Shared/ReactiveAppWindow.cs index 58f4ad820..a751f4ee6 100644 --- a/src/Artemis.UI.Shared/ReactiveAppWindow.cs +++ b/src/Artemis.UI.Shared/ReactiveAppWindow.cs @@ -48,7 +48,7 @@ public class ReactiveAppWindow : AppWindow, IViewFor whe return; TransparencyBackgroundFallback = Brushes.Transparent; - TransparencyLevelHint = WindowTransparencyLevel.Mica; + TransparencyLevelHint = new[] {WindowTransparencyLevel.Mica}; TryEnableMicaEffect(); } diff --git a/src/Artemis.UI.Shared/Utilities.cs b/src/Artemis.UI.Shared/Utilities.cs index cb2d58992..367e6b05c 100644 --- a/src/Artemis.UI.Shared/Utilities.cs +++ b/src/Artemis.UI.Shared/Utilities.cs @@ -1,7 +1,5 @@ using System; -using System.ComponentModel; using System.Reactive.Linq; -using System.Reactive.Subjects; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Input.Platform; @@ -14,12 +12,9 @@ namespace Artemis.UI.Shared; /// public static class UI { - private static readonly BehaviorSubject KeyBindingsEnabledSubject = new(false); - static UI() { - if (KeyboardDevice.Instance != null) - KeyboardDevice.Instance.PropertyChanged += InstanceOnPropertyChanged; + KeyBindingsEnabled = InputElement.GotFocusEvent.Raised.Select(e => e.Item2.Source is not TextBox); } /// @@ -35,15 +30,5 @@ public static class UI /// /// Gets a boolean indicating whether hotkeys are to be disabled. /// - public static IObservable KeyBindingsEnabled { get; } = KeyBindingsEnabledSubject.AsObservable(); - - private static void InstanceOnPropertyChanged(object? sender, PropertyChangedEventArgs e) - { - if (KeyboardDevice.Instance == null || e.PropertyName != nameof(KeyboardDevice.FocusedElement)) - return; - - bool enabled = KeyboardDevice.Instance.FocusedElement is not TextBox; - if (KeyBindingsEnabledSubject.Value != enabled) - KeyBindingsEnabledSubject.OnNext(enabled); - } + public static IObservable KeyBindingsEnabled { get; } } \ No newline at end of file diff --git a/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj b/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj index bdea0536c..3910a5e65 100644 --- a/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj +++ b/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj @@ -21,12 +21,12 @@ - - + + - - - + + + diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index ce2eaaf18..47da417f7 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -15,20 +15,20 @@ - - - + + + - - - + + + - + - - + + diff --git a/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs b/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs index bd3845bfa..b23346427 100644 --- a/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs +++ b/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs @@ -103,8 +103,9 @@ public class SimpleContextDragBehavior : Behavior private void AssociatedObject_PointerPressed(object? sender, PointerPressedEventArgs e) { + IFocusManager? focusManager = TopLevel.GetTopLevel(AssociatedObject)?.FocusManager; PointerPointProperties properties = e.GetCurrentPoint(AssociatedObject).Properties; - if (!properties.IsLeftButtonPressed || FocusManager.Instance?.Current is TextBox) + if (!properties.IsLeftButtonPressed || focusManager?.GetFocusedElement() is TextBox) return; if (e.Source is not Control control || AssociatedObject?.DataContext != control.DataContext) return; @@ -130,8 +131,9 @@ public class SimpleContextDragBehavior : Behavior private async void AssociatedObject_PointerMoved(object? sender, PointerEventArgs e) { + IFocusManager? focusManager = TopLevel.GetTopLevel(AssociatedObject)?.FocusManager; PointerPointProperties properties = e.GetCurrentPoint(AssociatedObject).Properties; - if (!properties.IsLeftButtonPressed || FocusManager.Instance?.Current is TextBox) + if (!properties.IsLeftButtonPressed || focusManager?.GetFocusedElement() is TextBox) return; if (_triggerEvent is null) diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs index 1ef4838a8..9063787d5 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs @@ -1,5 +1,4 @@ using Avalonia.Input; -using Avalonia.Markup.Xaml; using Avalonia.ReactiveUI; namespace Artemis.UI.DefaultTypes.PropertyInput; @@ -16,6 +15,6 @@ public partial class StringPropertyInputView : ReactiveUserControl - + diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml index f3914a73f..ade53ea24 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml @@ -110,14 +110,14 @@ - diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs index 833a56e20..797cad4d5 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs @@ -5,7 +5,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.PanAndZoom; using Avalonia.Input; -using Avalonia.Markup.Xaml; using Avalonia.Media; using Avalonia.ReactiveUI; @@ -30,7 +29,7 @@ public partial class SurfaceEditorView : ReactiveUserControl { - private Canvas? _container; + private readonly DispatcherTimer _updateTimer; private bool _dragging; + private Canvas? _container; private Border? _pinPoint; - private PinViewRenderLoopTaks _renderLoopTask; + + public PinView() + { + _updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(16), DispatcherPriority.Render, UpdatePosition); + } protected void InitializePin(Border pinPoint) { @@ -21,7 +26,6 @@ public class PinView : ReactiveUserControl _pinPoint.PointerMoved += PinPointOnPointerMoved; _pinPoint.PointerReleased += PinPointOnPointerReleased; _pinPoint.PropertyChanged += PinPointOnPropertyChanged; - _renderLoopTask = new PinViewRenderLoopTaks(this); } private void PinPointOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) @@ -74,19 +78,17 @@ public class PinView : ReactiveUserControl /// protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { - base.OnAttachedToVisualTree(e); _container = this.FindAncestorOfType(); - AvaloniaLocator.Current.GetRequiredService().Add(_renderLoopTask); + _updateTimer.Start(); } /// protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { - base.OnDetachedFromVisualTree(e); - AvaloniaLocator.Current.GetRequiredService().Remove(_renderLoopTask); + _updateTimer.Stop(); } - public void UpdatePosition() + public void UpdatePosition(object? sender, EventArgs eventArgs) { if (_container == null || _pinPoint == null || ViewModel == null) return; @@ -97,25 +99,4 @@ public class PinView : ReactiveUserControl } #endregion -} - -public class PinViewRenderLoopTaks : IRenderLoopTask -{ - private readonly PinView _pinView; - - public PinViewRenderLoopTaks(PinView pinView) - { - _pinView = pinView; - } - - public void Update(TimeSpan time) - { - _pinView.UpdatePosition(); - } - - public void Render() - { - } - - public bool NeedsUpdate => true; } \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj b/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj index 2a69a2d53..c0e7a1bec 100644 --- a/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj +++ b/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj @@ -8,9 +8,9 @@ - - - + + +