Core - Ensure devices owned by ArtemisDevice always have valid dimensions

This commit is contained in:
Robert committed 2023-10-14 19:36:46 +02:00
1 parent 76d424012a
commit 38f18613c1
3 files changed
+38 -9

No files matched your search

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
@@ -37,6 +39,12 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
DetectInput = ReactiveCommand.CreateFromTask(ExecuteDetectInput, this.WhenAnyValue(vm => vm.CanDetectInput));
X = device.X;
Y = device.Y;
this.WhenActivated(d =>
{
Device.PropertyChanged += DeviceOnPropertyChanged;
Disposable.Create(() => Device.PropertyChanged -= DeviceOnPropertyChanged).DisposeWith(d);
});
}
public ReactiveCommand<Unit, Unit> DetectInput { get; }
@@ -143,4 +151,12 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
Device.X = X;
Device.Y = Y;
}
private void DeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Device.X))
X = Device.X;
if (e.PropertyName == nameof(Device.Y))
Y = Device.Y;
}
}