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

Devices - Added option to disable default layouts

This commit is contained in:
Robert 2021-06-03 11:10:07 +02:00
parent fb3f7e0cc1
commit cef37677f2
6 changed files with 117 additions and 10 deletions

View File

@ -33,6 +33,8 @@ namespace Artemis.Core
BlueScale = 1;
IsEnabled = true;
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(new Dictionary<LedId, ArtemisLed>());
Leds = new ReadOnlyCollection<ArtemisLed>(new List<ArtemisLed>());
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
InputMappings = new Dictionary<ArtemisLed, ArtemisLed>();
Categories = new HashSet<DeviceCategory>();
@ -51,6 +53,8 @@ namespace Artemis.Core
RgbDevice = rgbDevice;
DeviceProvider = deviceProvider;
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(new Dictionary<LedId, ArtemisLed>());
Leds = new ReadOnlyCollection<ArtemisLed>(new List<ArtemisLed>());
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
InputMappings = new Dictionary<ArtemisLed, ArtemisLed>();
Categories = new HashSet<DeviceCategory>();
@ -258,6 +262,19 @@ namespace Artemis.Core
}
}
/// <summary>
/// Gets or sets a boolean indicating whether falling back to default layouts is enabled or not
/// </summary>
public bool DisableDefaultLayout
{
get => DeviceEntity.DisableDefaultLayout;
set
{
DeviceEntity.DisableDefaultLayout = value;
OnPropertyChanged(nameof(DisableDefaultLayout));
}
}
/// <summary>
/// Gets or sets the logical layout of the device e.g. DE, UK or US.
/// <para>Only applicable to keyboards</para>
@ -532,6 +549,11 @@ namespace Artemis.Core
else
LogicalLayout = DeviceEntity.LogicalLayout;
}
public void ClearLayout()
{
// TODO
}
}
/// <summary>

View File

@ -354,19 +354,26 @@ namespace Artemis.Core.Services
}
// Finally fall back to a default layout
layout = ArtemisLayout.GetDefaultLayout(device);
if (layout != null)
ApplyDeviceLayout(device, layout);
if (!device.DisableDefaultLayout)
layout = ArtemisLayout.GetDefaultLayout(device);
ApplyDeviceLayout(device, layout);
return layout;
}
public void ApplyDeviceLayout(ArtemisDevice device, ArtemisLayout layout)
public void ApplyDeviceLayout(ArtemisDevice device, ArtemisLayout? layout)
{
if (layout == null)
{
if (device.Layout != null)
device.ClearLayout();
return;
}
if (layout.Source == LayoutSource.Default)
device.ApplyLayout(layout, false, false);
else
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
UpdateLedGroup();
}

View File

@ -22,6 +22,7 @@ namespace Artemis.Storage.Entities.Surface
public float BlueScale { get; set; }
public bool IsEnabled { get; set; }
public bool DisableDefaultLayout { get; set; }
public int PhysicalLayout { get; set; }
public string LogicalLayout { get; set; }
public string CustomLayoutPath { get; set; }

View File

@ -0,0 +1,41 @@
using System.Windows.Documents;
using System.Windows.Navigation;
using Artemis.Core;
using Microsoft.Xaml.Behaviors;
namespace Artemis.UI.Shared
{
/// <summary>
/// Represents a behavior that opens the URI of the hyperlink in the browser when requested
/// </summary>
public class OpenInBrowser : Behavior<Hyperlink>
{
private Hyperlink? _hyperLink;
/// <inheritdoc />
protected override void OnAttached()
{
base.OnAttached();
_hyperLink = AssociatedObject;
if (_hyperLink == null)
return;
_hyperLink.RequestNavigate += HyperLinkOnRequestNavigate;
}
/// <inheritdoc />
protected override void OnDetaching()
{
if (_hyperLink == null) return;
_hyperLink.RequestNavigate -= HyperLinkOnRequestNavigate;
base.OnDetaching();
}
private void HyperLinkOnRequestNavigate(object sender, RequestNavigateEventArgs e)
{
Utilities.OpenUrl(e.Uri.AbsoluteUri);
}
}
}

View File

@ -7,6 +7,7 @@
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:DevicePropertiesTabViewModel}">
@ -29,7 +30,7 @@
Foreground="{DynamicResource MaterialDesignBodyLight}"
TextWrapping="Wrap"
TextAlignment="Justify">
Artemis uses categories to determine where the layers of imported profiles are applied to. <LineBreak/>
Artemis uses categories to determine where the layers of imported profiles are applied to. <LineBreak />
You can hover over a category for a more detailed description.
</TextBlock>
<StackPanel Orientation="Horizontal">
@ -192,15 +193,25 @@
<!-- Layout -->
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}">
Custom layout
Layout
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignCaptionTextBlock}"
Foreground="{DynamicResource MaterialDesignBodyLight}"
TextWrapping="Wrap"
TextAlignment="Justify">
Select a custom layout below if you want to change the appearance and/or LEDs of this device.
The device layout is used to determine the position of LEDs and to create the visual representation of the device you see on the left side of this window.
</TextBlock>
<CheckBox Margin="0 0 0 5" Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding UseDefaultLayout}">
<CheckBox.Content>
<TextBlock Margin="0 -5 0 0">
Use default layout if needed
<materialDesign:PackIcon Kind="HelpCircle"
ToolTip="If there is no built-in layout and no custom layout, with this enabled Artemis will fall back to the default layout of this device type." />
</TextBlock>
</CheckBox.Content>
</CheckBox>
<TextBox Style="{StaticResource MaterialDesignFilledTextBox}"
Text="{Binding Device.CustomLayoutPath}"
VerticalAlignment="Center"
@ -210,10 +221,25 @@
<materialDesign:HintAssist.Hint>
<StackPanel Orientation="Horizontal" Margin="-2 0 0 0">
<materialDesign:PackIcon Kind="Xml" Width="20" />
<TextBlock>Layout path</TextBlock>
<TextBlock>Custom layout path</TextBlock>
</StackPanel>
</materialDesign:HintAssist.Hint>
</TextBox>
<TextBlock Style="{StaticResource MaterialDesignCaptionTextBlock}"
Foreground="{DynamicResource MaterialDesignBodyLight}"
TextWrapping="Wrap"
TextAlignment="Justify">
Select a custom layout below if you want to change the appearance and/or LEDs of this device.
For info on how to create layouts, check out
<Hyperlink Style="{StaticResource ArtemisHyperlink}"
NavigateUri="https://wiki.artemis-rgb.com/en/guides/developer/layouts">
this wiki article
<b:Interaction.Behaviors>
<shared:OpenInBrowser />
</b:Interaction.Behaviors>
</Hyperlink>
.
</TextBlock>
</StackPanel>
<!-- Buttons -->

View File

@ -134,6 +134,16 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs
set => SetCategory(DeviceCategory.Peripherals, value);
}
public bool UseDefaultLayout
{
get => !Device.DisableDefaultLayout;
set
{
Device.DisableDefaultLayout = !value;
NotifyOfPropertyChange(nameof(UseDefaultLayout));
}
}
public void ApplyScaling()
{
Device.RedScale = RedScale / 100f;
@ -255,7 +265,7 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs
private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Device.CustomLayoutPath))
if (e.PropertyName == nameof(Device.CustomLayoutPath) || e.PropertyName == nameof(Device.DisableDefaultLayout))
_rgbService.ApplyBestDeviceLayout(Device);
}