1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 01:42:02 +00:00

Fixed freeze when changing active surface config

This commit is contained in:
SpoinkyNL 2019-10-27 22:19:42 +01:00
parent ce383468ea
commit 498b6a6111
3 changed files with 22 additions and 18 deletions

View File

@ -27,7 +27,7 @@ namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
} }
} }
public SurfaceDeviceConfiguration DeviceConfiguration { get; } public SurfaceDeviceConfiguration DeviceConfiguration { get; set; }
public SelectionStatus SelectionStatus { get; set; } public SelectionStatus SelectionStatus { get; set; }
public Cursor Cursor { get; set; } public Cursor Cursor { get; set; }

View File

@ -8,18 +8,22 @@ namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
public SurfaceLedViewModel(Led led) public SurfaceLedViewModel(Led led)
{ {
Led = led; Led = led;
ApplyLedToViewModel();
}
public void ApplyLedToViewModel()
{
X = Led.LedRectangle.X; X = Led.LedRectangle.X;
Y = Led.LedRectangle.Y; Y = Led.LedRectangle.Y;
Width = Led.LedRectangle.Width; Width = Led.LedRectangle.Width;
Height = Led.LedRectangle.Height; Height = Led.LedRectangle.Height;
} }
public Led Led { get; } public Led Led { get; set; }
public double X { get; } public double X { get; set; }
public double Y { get; } public double Y { get; set; }
public double Width { get; } public double Width { get; set; }
public double Height { get; } public double Height { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -89,18 +90,17 @@ namespace Artemis.UI.ViewModels.Screens
return; return;
} }
Task.Run(() => // Make sure all devices have an up-to-date VM
foreach (var surfaceDeviceConfiguration in SelectedSurfaceConfiguration.DeviceConfigurations)
{ {
// Create VMs for the new config outside the UI thread // Create VMs for missing devices
var viewModels = SelectedSurfaceConfiguration.DeviceConfigurations.Select(c => new SurfaceDeviceViewModel(c)).ToList(); var viewModel = Devices.FirstOrDefault(vm => vm.DeviceConfiguration.Device == surfaceDeviceConfiguration.Device);
// Commit the VMs to the view if (viewModel == null)
Execute.OnUIThread(() => Execute.OnUIThread(() => Devices.Add(new SurfaceDeviceViewModel(surfaceDeviceConfiguration)));
{ // Update existing devices
Devices.Clear(); else
foreach (var viewModel in viewModels.OrderBy(v => v.ZIndex)) viewModel.DeviceConfiguration = surfaceDeviceConfiguration;
Devices.Add(viewModel); }
});
});
_surfaceService.SetActiveSurfaceConfiguration(SelectedSurfaceConfiguration); _surfaceService.SetActiveSurfaceConfiguration(SelectedSurfaceConfiguration);
} }
@ -122,7 +122,7 @@ namespace Artemis.UI.ViewModels.Screens
var result = await _dialogService.ShowConfirmDialogAt( var result = await _dialogService.ShowConfirmDialogAt(
"SurfaceListDialogHost", "SurfaceListDialogHost",
"Delete surface configuration", "Delete surface configuration",
"Are you sure you want to delete this surface configuration?" "Are you sure you want to delete\nthis surface configuration?"
); );
if (result) if (result)
{ {