1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Profile editor - Performance improvements

This commit is contained in:
SpoinkyNL 2020-09-14 19:54:09 +02:00
parent 447112729d
commit 1d789bf23c
13 changed files with 58 additions and 83 deletions

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
internal class PercentageOfModifierType : DataBindingModifierType
{
public PercentageOfModifierType()
{
PreferredParameterType = typeof(float);
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Percentage of";
public override string Icon => "Percent";
public override object Apply(object currentValue, object parameterValue)
{
var parameter = Convert.ToSingle(parameterValue);
// Ye ye none of that
if (parameter == 0f)
return 100f;
return 100f / Convert.ToSingle(parameterValue) * Convert.ToSingle(currentValue);
}
}
}

View File

@ -42,6 +42,7 @@ namespace Artemis.Core.Services
private void RegisterBuiltInModifiers() private void RegisterBuiltInModifiers()
{ {
RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType()); RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType());
RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType());
RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType()); RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType());
RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType()); RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType());
} }

View File

@ -5,9 +5,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="https://github.com/canton7/Stylet" xmlns:s="https://github.com/canton7/Stylet"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:modules="clr-namespace:Artemis.UI.Screens.Modules"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance module:ModuleRootViewModel}"> d:DataContext="{d:DesignInstance modules:ModuleRootViewModel}">
<TabControl Margin="0 -1 0 0" <TabControl Margin="0 -1 0 0"
ItemsSource="{Binding Items}" ItemsSource="{Binding Items}"
@ -17,7 +18,7 @@
<TabControl.ContentTemplate> <TabControl.ContentTemplate>
<DataTemplate> <DataTemplate>
<materialDesign:TransitioningContent OpeningEffect="{materialDesign:TransitionEffect FadeIn}"> <materialDesign:TransitioningContent OpeningEffect="{materialDesign:TransitionEffect FadeIn}">
<ContentControl s:View.Model="{Binding}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" /> <ContentControl s:View.Model="{Binding IsAsync=True}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" />
</materialDesign:TransitioningContent> </materialDesign:TransitioningContent>
</DataTemplate> </DataTemplate>
</TabControl.ContentTemplate> </TabControl.ContentTemplate>

View File

@ -102,7 +102,7 @@
<ContentControl s:View.Model="{Binding TreeGroupViewModel}" /> <ContentControl s:View.Model="{Binding TreeGroupViewModel}" />
</HierarchicalDataTemplate> </HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:LayerPropertyViewModel}"> <DataTemplate DataType="{x:Type local:LayerPropertyViewModel}">
<ContentControl s:View.Model="{Binding TreePropertyViewModel}" dd:DragDrop.DragSourceIgnore="True" /> <ContentControl s:View.Model="{Binding TreePropertyViewModel, IsAsync=True}" dd:DragDrop.DragSourceIgnore="True" />
</DataTemplate> </DataTemplate>
</TreeView.Resources> </TreeView.Resources>
</TreeView> </TreeView>

View File

@ -86,7 +86,7 @@
<!-- Design area --> <!-- Design area -->
<materialDesign:Card Grid.Row="1" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch"> <materialDesign:Card Grid.Row="1" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding ProfileViewModel}" /> <ContentControl s:View.Model="{Binding ProfileViewModel, IsAsync=True}" />
</materialDesign:Card> </materialDesign:Card>
<!-- Bottom panels resize --> <!-- Bottom panels resize -->
@ -96,7 +96,7 @@
<Grid Grid.Row="3"> <Grid Grid.Row="3">
<!-- Layer elements --> <!-- Layer elements -->
<materialDesign:Card Grid.Column="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch"> <materialDesign:Card Grid.Column="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding LayerPropertiesViewModel}" /> <ContentControl s:View.Model="{Binding LayerPropertiesViewModel, IsAsync=True}" />
</materialDesign:Card> </materialDesign:Card>
</Grid> </Grid>
</Grid> </Grid>
@ -179,7 +179,7 @@
<!-- Profile elements --> <!-- Profile elements -->
<materialDesign:Card Grid.Row="1" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch"> <materialDesign:Card Grid.Row="1" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding ProfileTreeViewModel}" Margin="0,-1,-0.2,1" /> <ContentControl s:View.Model="{Binding ProfileTreeViewModel, IsAsync=True}" Margin="0,-1,-0.2,1" />
</materialDesign:Card> </materialDesign:Card>
<!-- Conditions resize --> <!-- Conditions resize -->
@ -187,7 +187,7 @@
<!-- Display conditions --> <!-- Display conditions -->
<materialDesign:Card Grid.Row="3" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch"> <materialDesign:Card Grid.Row="3" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding DisplayConditionsViewModel}" /> <ContentControl s:View.Model="{Binding DisplayConditionsViewModel, IsAsync=True}" />
</materialDesign:Card> </materialDesign:Card>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -10,36 +10,6 @@
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="510.9" d:DesignWidth="800" d:DesignHeight="510.9" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type visualization:ProfileViewModel}}"> d:DataContext="{d:DesignInstance {x:Type visualization:ProfileViewModel}}">
<UserControl.Resources>
<Style TargetType="Grid" x:Key="InitializingFade">
<Style.Triggers>
<DataTrigger Binding="{Binding IsInitializing}" Value="False">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1.0" To="0.0" Duration="0:0:0.5">
<DoubleAnimation.EasingFunction>
<QuadraticEase EasingMode="EaseInOut" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:0.5" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Hidden}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
@ -186,16 +156,6 @@
<materialDesign:PackIcon Kind="ImageFilterCenterFocus" Height="24" Width="24" /> <materialDesign:PackIcon Kind="ImageFilterCenterFocus" Height="24" Width="24" />
</Button> </Button>
</StackPanel> </StackPanel>
<!-- Loading indicator -->
<Grid Background="{StaticResource MaterialDesignPaper}" Style="{StaticResource InitializingFade}" d:IsHidden="True">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center">
Initializing LED visualization...
</TextBlock>
<ProgressBar Style="{StaticResource MaterialDesignCircularProgressBar}" Value="0" IsIndeterminate="True" />
</StackPanel>
</Grid>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -41,7 +41,7 @@
<DataTrigger.ExitActions> <DataTrigger.ExitActions>
<BeginStoryboard> <BeginStoryboard>
<Storyboard> <Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:0.4" /> <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:0.25" />
</Storyboard> </Storyboard>
</BeginStoryboard> </BeginStoryboard>
</DataTrigger.ExitActions> </DataTrigger.ExitActions>

View File

@ -8,6 +8,7 @@ using System.Windows.Input;
using Artemis.Core; using Artemis.Core;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Events; using Artemis.UI.Events;
using Artemis.UI.Screens.Modules;
using Artemis.UI.Screens.Settings.Tabs.General; using Artemis.UI.Screens.Settings.Tabs.General;
using Artemis.UI.Screens.Sidebar; using Artemis.UI.Screens.Sidebar;
using Artemis.UI.Services; using Artemis.UI.Services;
@ -139,8 +140,10 @@ namespace Artemis.UI.Screens
if (e.PropertyName == nameof(SidebarViewModel.SelectedItem) && ActiveItem != SidebarViewModel.SelectedItem) if (e.PropertyName == nameof(SidebarViewModel.SelectedItem) && ActiveItem != SidebarViewModel.SelectedItem)
{ {
SidebarViewModel.IsSidebarOpen = false; SidebarViewModel.IsSidebarOpen = false;
ActiveItemReady = false; // Don't do a fade when selecting a module because the editor is so bulky the animation slows things down
if (!(SidebarViewModel.SelectedItem is ModuleRootViewModel))
ActiveItemReady = false;
// Allow the menu to close, it's slower but feels more responsive, funny how that works right // Allow the menu to close, it's slower but feels more responsive, funny how that works right
Execute.PostToUIThreadAsync(async () => Execute.PostToUIThreadAsync(async () =>
{ {

View File

@ -22,7 +22,7 @@
DisplayMemberPath="DisplayName"> DisplayMemberPath="DisplayName">
<TabControl.ContentTemplate> <TabControl.ContentTemplate>
<DataTemplate> <DataTemplate>
<ContentControl s:View.Model="{Binding}" <ContentControl s:View.Model="{Binding IsAsync=True}"
VerticalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
IsTabStop="False" IsTabStop="False"

View File

@ -11,7 +11,7 @@
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0 12 0 0"> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0 12 0 0">
<DockPanel Margin="15" MaxWidth="1230" HorizontalAlignment="Center"> <DockPanel Margin="15" MaxWidth="1230" HorizontalAlignment="Center">
<TextBlock DockPanel.Dock="Top">Below you view and manage the devices that were detected by Artemis</TextBlock> <TextBlock DockPanel.Dock="Top">Below you view and manage the devices that were detected by Artemis</TextBlock>
<ItemsControl ItemsSource="{Binding DeviceSettingsViewModels}"> <ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<WrapPanel /> <WrapPanel />
@ -19,7 +19,7 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<ContentControl s:View.Model="{Binding}" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top" /> <ContentControl s:View.Model="{Binding IsAsync=True}" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top" />
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>

View File

@ -6,7 +6,7 @@ using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Devices namespace Artemis.UI.Screens.Settings.Tabs.Devices
{ {
public class DeviceSettingsTabViewModel : Screen public class DeviceSettingsTabViewModel : Conductor<DeviceSettingsViewModel>.Collection.AllActive
{ {
private readonly ISettingsVmFactory _settingsVmFactory; private readonly ISettingsVmFactory _settingsVmFactory;
private readonly ISurfaceService _surfaceService; private readonly ISurfaceService _surfaceService;
@ -18,25 +18,17 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
_surfaceService = surfaceService; _surfaceService = surfaceService;
_settingsVmFactory = settingsVmFactory; _settingsVmFactory = settingsVmFactory;
DeviceSettingsViewModels = new BindableCollection<DeviceSettingsViewModel>();
} }
public BindableCollection<DeviceSettingsViewModel> DeviceSettingsViewModels
{
get => _deviceSettingsViewModels;
set => SetAndNotify(ref _deviceSettingsViewModels, value);
}
protected override void OnActivate() protected override void OnActivate()
{ {
// Take it off the UI thread to avoid freezing on tab change // Take it off the UI thread to avoid freezing on tab change
Task.Run(() => Task.Run(() =>
{ {
DeviceSettingsViewModels.Clear(); Items.Clear();
var instances = _surfaceService.ActiveSurface.Devices.Select(d => _settingsVmFactory.CreateDeviceSettingsViewModel(d)).ToList(); var instances = _surfaceService.ActiveSurface.Devices.Select(d => _settingsVmFactory.CreateDeviceSettingsViewModel(d)).ToList();
foreach (var deviceSettingsViewModel in instances) foreach (var deviceSettingsViewModel in instances)
DeviceSettingsViewModels.Add(deviceSettingsViewModel); Items.Add(deviceSettingsViewModel);
}); });
} }
} }

View File

@ -5,13 +5,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.Plugins" xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.Plugins"
xmlns:s="https://github.com/canton7/Stylet" xmlns:s="https://github.com/canton7/Stylet"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:PluginSettingsTabViewModel}"> d:DataContext="{d:DesignInstance local:PluginSettingsTabViewModel}">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0 12 0 0"> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0 12 0 0">
<DockPanel Margin="15" MaxWidth="1230" HorizontalAlignment="Center"> <DockPanel Margin="15" MaxWidth="1230" HorizontalAlignment="Center">
<TextBlock DockPanel.Dock="Top">The list below shows all loaded plugins. If you're missing something, view your logs folder.</TextBlock> <TextBlock DockPanel.Dock="Top">The list below shows all loaded plugins. If you're missing something, view your logs folder.</TextBlock>
<ItemsControl ItemsSource="{Binding Plugins}"> <ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<WrapPanel /> <WrapPanel />
@ -19,7 +20,7 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<ContentControl s:View.Model="{Binding}" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top" /> <ContentControl s:View.Model="{Binding IsAsync=True}" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top" />
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>

View File

@ -6,7 +6,7 @@ using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Plugins namespace Artemis.UI.Screens.Settings.Tabs.Plugins
{ {
public class PluginSettingsTabViewModel : Screen public class PluginSettingsTabViewModel : Conductor<PluginSettingsViewModel>.Collection.AllActive
{ {
private readonly IPluginService _pluginService; private readonly IPluginService _pluginService;
private readonly ISettingsVmFactory _settingsVmFactory; private readonly ISettingsVmFactory _settingsVmFactory;
@ -18,26 +18,15 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
_pluginService = pluginService; _pluginService = pluginService;
_settingsVmFactory = settingsVmFactory; _settingsVmFactory = settingsVmFactory;
Plugins = new BindableCollection<PluginSettingsViewModel>();
}
public BindableCollection<PluginSettingsViewModel> Plugins
{
get => _plugins;
set => SetAndNotify(ref _plugins, value);
} }
protected override void OnActivate() protected override void OnActivate()
{ {
// Take it off the UI thread to avoid freezing on tab change // Take it off the UI thread to avoid freezing on tab change
Task.Run(() => Items.Clear();
{ var instances = _pluginService.GetAllPluginInfo().Select(p => _settingsVmFactory.CreatePluginSettingsViewModel(p.Instance)).ToList();
Plugins.Clear(); foreach (var pluginSettingsViewModel in instances)
var instances = _pluginService.GetAllPluginInfo().Select(p => _settingsVmFactory.CreatePluginSettingsViewModel(p.Instance)).ToList(); Items.Add(pluginSettingsViewModel);
foreach (var pluginSettingsViewModel in instances)
Plugins.Add(pluginSettingsViewModel);
});
} }
} }
} }