1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Merge pull request #807 from Artemis-RGB/feature/fix-layouts

UI - Fix layout loading
This commit is contained in:
RobertBeekman 2023-08-19 20:47:59 +02:00 committed by GitHub
commit bb3bc576db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 22 deletions

View File

@ -66,13 +66,11 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase
this.WhenActivated(d => this.WhenActivated(d =>
{ {
Device.PropertyChanged += DeviceOnPropertyChanged;
_coreService.FrameRendering += OnFrameRendering; _coreService.FrameRendering += OnFrameRendering;
Disposable.Create(() => Disposable.Create(() =>
{ {
_coreService.FrameRendering -= OnFrameRendering; _coreService.FrameRendering -= OnFrameRendering;
Device.PropertyChanged -= DeviceOnPropertyChanged;
Apply(); Apply();
}).DisposeWith(d); }).DisposeWith(d);
}); });
@ -244,10 +242,4 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase
using SKPaint overlayPaint = new() { Color = CurrentColor }; using SKPaint overlayPaint = new() { Color = CurrentColor };
e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint); e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint);
} }
private void DeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Device.CustomLayoutPath) || e.PropertyName == nameof(Device.DisableDefaultLayout))
Task.Run(() => _rgbService.ApplyBestDeviceLayout(Device));
}
} }

View File

@ -21,6 +21,7 @@
<Button <Button
Classes="icon-button" Classes="icon-button"
HorizontalAlignment="Right" HorizontalAlignment="Right"
IsEnabled="{CompiledBinding !!DefaultLayoutPath}"
ToolTip.Tip="Copy layout file path to clipboard" ToolTip.Tip="Copy layout file path to clipboard"
Click="LayoutPathButton_OnClick"> Click="LayoutPathButton_OnClick">
<avalonia:MaterialIcon Kind="ContentCopy" Width="18" Height="18" /> <avalonia:MaterialIcon Kind="ContentCopy" Width="18" Height="18" />
@ -31,12 +32,13 @@
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto"> <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Row="1" Grid.Column="0"> <StackPanel Grid.Row="1" Grid.Column="0">
<TextBlock Text="Image file path" /> <TextBlock Text="Image file path" />
<TextBlock Classes="subtitle" FontSize="12" TextWrapping="Wrap" Text="{CompiledBinding Device.Layout.Image.LocalPath}" /> <TextBlock Classes="subtitle" FontSize="12" TextWrapping="Wrap" Text="{CompiledBinding ImagePath, TargetNullValue=None}" />
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"> <StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">
<Button <Button
Classes="icon-button" Classes="icon-button"
HorizontalAlignment="Right" HorizontalAlignment="Right"
IsEnabled="{CompiledBinding !!ImagePath}"
ToolTip.Tip="Copy image file path to clipboard" ToolTip.Tip="Copy image file path to clipboard"
Click="ImagePathButton_OnClick"> Click="ImagePathButton_OnClick">
<avalonia:MaterialIcon Kind="ContentCopy" Width="18" Height="18" /> <avalonia:MaterialIcon Kind="ContentCopy" Width="18" Height="18" />
@ -50,14 +52,14 @@
<TextBlock Classes="subtitle" FontSize="12" Text="With this checked, Artemis will not load a layout for this device unless you specifically provide one." /> <TextBlock Classes="subtitle" FontSize="12" Text="With this checked, Artemis will not load a layout for this device unless you specifically provide one." />
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"> <StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">
<CheckBox HorizontalAlignment="Right" Margin="0,0,-10,0" /> <CheckBox HorizontalAlignment="Right" Margin="0,0,-10,0" IsChecked="{CompiledBinding Device.DisableDefaultLayout}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Border Classes="card-separator" /> <Border Classes="card-separator" />
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto"> <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Row="1" Grid.Column="0"> <StackPanel Grid.Row="1" Grid.Column="0">
<TextBlock Text="Custom layout path" /> <TextBlock Text="Custom layout path" />
<TextBlock Classes="subtitle" FontSize="12" Text="{CompiledBinding CustomLayoutPath}" /> <TextBlock Classes="subtitle" FontSize="12" Text="{CompiledBinding CustomLayoutPath, TargetNullValue=None}"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal"> <StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal">
<Button Content="Clear" Command="{CompiledBinding ClearCustomLayout}" IsEnabled="{CompiledBinding HasCustomLayout}" /> <Button Content="Clear" Command="{CompiledBinding ClearCustomLayout}" IsEnabled="{CompiledBinding HasCustomLayout}" />

View File

@ -16,12 +16,18 @@ public partial class DeviceLayoutTabView : ReactiveUserControl<DeviceLayoutTabVi
private void LayoutPathButton_OnClick(object? sender, RoutedEventArgs e) private void LayoutPathButton_OnClick(object? sender, RoutedEventArgs e)
{ {
if (ViewModel?.DefaultLayoutPath is null)
return;
TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(ViewModel.DefaultLayoutPath); TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(ViewModel.DefaultLayoutPath);
ViewModel.ShowCopiedNotification(); ViewModel.ShowCopiedNotification();
} }
private void ImagePathButton_OnClick(object? sender, RoutedEventArgs e) private void ImagePathButton_OnClick(object? sender, RoutedEventArgs e)
{ {
if (ViewModel?.Device?.Layout?.Image?.LocalPath is null)
return;
TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(ViewModel.Device.Layout.Image.LocalPath); TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(ViewModel.Device.Layout.Image.LocalPath);
ViewModel.ShowCopiedNotification(); ViewModel.ShowCopiedNotification();
} }

View File

@ -22,42 +22,52 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase
{ {
private readonly IWindowService _windowService; private readonly IWindowService _windowService;
private readonly INotificationService _notificationService; private readonly INotificationService _notificationService;
private readonly ICoreService _coreService;
private readonly IRgbService _rgbService;
public DeviceLayoutTabViewModel( public DeviceLayoutTabViewModel(
IWindowService windowService, IWindowService windowService,
INotificationService notificationService, INotificationService notificationService,
ICoreService coreService,
IRgbService rgbService,
ArtemisDevice device) ArtemisDevice device)
{ {
_windowService = windowService; _windowService = windowService;
_notificationService = notificationService; _notificationService = notificationService;
_coreService = coreService;
_rgbService = rgbService;
Device = device; Device = device;
DisplayName = "Layout"; DisplayName = "Layout";
DefaultLayoutPath = Device.DeviceProvider.LoadLayout(Device).FilePath; DefaultLayoutPath = Device.DeviceProvider.LoadLayout(Device).FilePath;
this.WhenActivated(d =>
{
Device.PropertyChanged += DeviceOnPropertyChanged;
Disposable.Create(() =>
{
Device.PropertyChanged -= DeviceOnPropertyChanged;
}).DisposeWith(d);
});
} }
public ArtemisDevice Device { get; } public ArtemisDevice Device { get; }
public string DefaultLayoutPath { get; } public string DefaultLayoutPath { get; }
public string CustomLayoutPath => Device.CustomLayoutPath ?? "None"; public string? ImagePath => Device.Layout?.Image?.LocalPath;
public string CustomLayoutPath => Device.CustomLayoutPath;
public bool HasCustomLayout => Device.CustomLayoutPath != null; public bool HasCustomLayout => Device.CustomLayoutPath != null;
private void RaiseCustomLayoutChanged()
{
this.RaisePropertyChanged(nameof(CustomLayoutPath));
this.RaisePropertyChanged(nameof(HasCustomLayout));
}
public void ClearCustomLayout() public void ClearCustomLayout()
{ {
Device.CustomLayoutPath = null; Device.CustomLayoutPath = null;
_notificationService.CreateNotification() _notificationService.CreateNotification()
.WithMessage("Cleared imported layout.") .WithMessage("Cleared imported layout.")
.WithSeverity(NotificationSeverity.Informational); .WithSeverity(NotificationSeverity.Informational);
RaiseCustomLayoutChanged();
} }
public async Task BrowseCustomLayout() public async Task BrowseCustomLayout()
@ -75,8 +85,6 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase
.WithMessage($"File loaded from {files[0]}") .WithMessage($"File loaded from {files[0]}")
.WithSeverity(NotificationSeverity.Informational); .WithSeverity(NotificationSeverity.Informational);
} }
RaiseCustomLayoutChanged();
} }
public async Task ExportLayout() public async Task ExportLayout()
@ -148,4 +156,10 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase
.WithSeverity(NotificationSeverity.Informational) .WithSeverity(NotificationSeverity.Informational)
.Show(); .Show();
} }
private void DeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(Device.CustomLayoutPath) or nameof(Device.DisableDefaultLayout))
Task.Run(() => _rgbService.ApplyBestDeviceLayout(Device));
}
} }