mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 18:23:32 +00:00
Data bindings - Update UI on registration changes
Data bindings - Tweaked UI tabs to handle a large amount of properties better Color gradient property - Update data binding properties on stop add/remove
This commit is contained in:
parent
f4ad41cbd4
commit
ef66511564
@ -1,10 +1,13 @@
|
|||||||
using SkiaSharp;
|
using System.ComponentModel;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public class ColorGradientLayerProperty : LayerProperty<ColorGradient>
|
public class ColorGradientLayerProperty : LayerProperty<ColorGradient>
|
||||||
{
|
{
|
||||||
|
private ColorGradient? _subscribedGradient;
|
||||||
|
|
||||||
internal ColorGradientLayerProperty()
|
internal ColorGradientLayerProperty()
|
||||||
{
|
{
|
||||||
KeyframesSupported = false;
|
KeyframesSupported = false;
|
||||||
@ -53,9 +56,23 @@ namespace Artemis.Core
|
|||||||
if (BaseValue == null)
|
if (BaseValue == null)
|
||||||
BaseValue = DefaultValue ?? new ColorGradient();
|
BaseValue = DefaultValue ?? new ColorGradient();
|
||||||
|
|
||||||
|
if (_subscribedGradient != BaseValue)
|
||||||
|
{
|
||||||
|
if (_subscribedGradient != null)
|
||||||
|
_subscribedGradient.PropertyChanged -= SubscribedGradientOnPropertyChanged;
|
||||||
|
_subscribedGradient = BaseValue;
|
||||||
|
_subscribedGradient.PropertyChanged += SubscribedGradientOnPropertyChanged;
|
||||||
|
}
|
||||||
|
|
||||||
CreateDataBindingRegistrations();
|
CreateDataBindingRegistrations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SubscribedGradientOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (CurrentValue.Stops.Count != GetAllDataBindingRegistrations().Count)
|
||||||
|
CreateDataBindingRegistrations();
|
||||||
|
}
|
||||||
|
|
||||||
#region Overrides of LayerProperty<ColorGradient>
|
#region Overrides of LayerProperty<ColorGradient>
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -97,6 +97,16 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<LayerPropertyEventArgs>? KeyframeRemoved;
|
public event EventHandler<LayerPropertyEventArgs>? KeyframeRemoved;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when a data binding property has been added
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<LayerPropertyEventArgs>? DataBindingPropertyRegistered;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when all data binding properties have been removed
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<LayerPropertyEventArgs>? DataBindingPropertiesCleared;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when a data binding has been enabled
|
/// Occurs when a data binding has been enabled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -419,6 +419,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
DataBindingRegistration<T, TProperty> registration = new(this, converter, getter, setter, displayName);
|
DataBindingRegistration<T, TProperty> registration = new(this, converter, getter, setter, displayName);
|
||||||
_dataBindingRegistrations.Add(registration);
|
_dataBindingRegistrations.Add(registration);
|
||||||
|
|
||||||
|
OnDataBindingPropertyRegistered();
|
||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,6 +433,7 @@ namespace Artemis.Core
|
|||||||
throw new ObjectDisposedException("LayerProperty");
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
_dataBindingRegistrations.Clear();
|
_dataBindingRegistrations.Clear();
|
||||||
|
OnDataBindingPropertiesCleared();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -667,6 +670,12 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event EventHandler<LayerPropertyEventArgs>? KeyframeRemoved;
|
public event EventHandler<LayerPropertyEventArgs>? KeyframeRemoved;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event EventHandler<LayerPropertyEventArgs>? DataBindingPropertyRegistered;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event EventHandler<LayerPropertyEventArgs>? DataBindingPropertiesCleared;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event EventHandler<LayerPropertyEventArgs>? DataBindingEnabled;
|
public event EventHandler<LayerPropertyEventArgs>? DataBindingEnabled;
|
||||||
|
|
||||||
@ -722,6 +731,22 @@ namespace Artemis.Core
|
|||||||
KeyframeRemoved?.Invoke(this, new LayerPropertyEventArgs(this));
|
KeyframeRemoved?.Invoke(this, new LayerPropertyEventArgs(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the <see cref="DataBindingPropertyRegistered" /> event
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnDataBindingPropertyRegistered()
|
||||||
|
{
|
||||||
|
DataBindingPropertyRegistered?.Invoke(this, new LayerPropertyEventArgs(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the <see cref="DataBindingDisabled" /> event
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnDataBindingPropertiesCleared()
|
||||||
|
{
|
||||||
|
DataBindingPropertiesCleared?.Invoke(this, new LayerPropertyEventArgs(this));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes the <see cref="DataBindingEnabled" /> event
|
/// Invokes the <see cref="DataBindingEnabled" /> event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -102,8 +102,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
|
|
||||||
protected override void OnInitialActivate()
|
protected override void OnInitialActivate()
|
||||||
{
|
{
|
||||||
base.OnInitialActivate();
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
base.OnInitialActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize()
|
||||||
|
|||||||
@ -6,11 +6,18 @@
|
|||||||
xmlns:s="https://github.com/canton7/Stylet"
|
xmlns:s="https://github.com/canton7/Stylet"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
<TabControl ItemsSource="{Binding Items}" SelectedIndex="{Binding SelectedItemIndex}" DisplayMemberPath="DisplayName" Style="{StaticResource MaterialDesignTabControl}">
|
<TabControl ItemsSource="{Binding Items}"
|
||||||
|
SelectedIndex="{Binding SelectedItemIndex}"
|
||||||
|
Style="{StaticResource MaterialDesignTabControl}" >
|
||||||
<TabControl.ContentTemplate>
|
<TabControl.ContentTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ContentControl s:View.Model="{Binding}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" />
|
<ContentControl s:View.Model="{Binding}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</TabControl.ContentTemplate>
|
</TabControl.ContentTemplate>
|
||||||
|
<TabControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Margin="-12 0" Text="{Binding DisplayName}"></TextBlock>
|
||||||
|
</DataTemplate>
|
||||||
|
</TabControl.ItemTemplate>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@ -1,5 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Ninject.Factories;
|
using Artemis.UI.Ninject.Factories;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
@ -11,7 +14,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
{
|
{
|
||||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||||
private readonly IProfileEditorService _profileEditorService;
|
private readonly IProfileEditorService _profileEditorService;
|
||||||
|
private ILayerProperty? _selectedDataBinding;
|
||||||
private int _selectedItemIndex;
|
private int _selectedItemIndex;
|
||||||
|
private bool _updating;
|
||||||
|
|
||||||
public DataBindingsViewModel(IProfileEditorService profileEditorService, IDataBindingsVmFactory dataBindingsVmFactory)
|
public DataBindingsViewModel(IProfileEditorService profileEditorService, IDataBindingsVmFactory dataBindingsVmFactory)
|
||||||
{
|
{
|
||||||
@ -24,9 +29,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
get => _selectedItemIndex;
|
get => _selectedItemIndex;
|
||||||
set => SetAndNotify(ref _selectedItemIndex, value);
|
set => SetAndNotify(ref _selectedItemIndex, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateDataBindingViewModels()
|
private void CreateDataBindingViewModels()
|
||||||
{
|
{
|
||||||
|
int oldIndex = SelectedItemIndex;
|
||||||
Items.Clear();
|
Items.Clear();
|
||||||
|
|
||||||
ILayerProperty layerProperty = _profileEditorService.SelectedDataBinding;
|
ILayerProperty layerProperty = _profileEditorService.SelectedDataBinding;
|
||||||
@ -37,26 +43,64 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
|
|
||||||
// Create a data binding VM for each data bindable property. These VMs will be responsible for retrieving
|
// Create a data binding VM for each data bindable property. These VMs will be responsible for retrieving
|
||||||
// and creating the actual data bindings
|
// and creating the actual data bindings
|
||||||
foreach (IDataBindingRegistration registration in registrations)
|
Items.AddRange(registrations.Select(registration => _dataBindingsVmFactory.DataBindingViewModel(registration)));
|
||||||
Items.Add(_dataBindingsVmFactory.DataBindingViewModel(registration));
|
|
||||||
|
|
||||||
SelectedItemIndex = 0;
|
SelectedItemIndex = Items.Count < oldIndex ? 0 : oldIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProfileEditorServiceOnSelectedDataBindingChanged(object sender, EventArgs e)
|
private void ProfileEditorServiceOnSelectedDataBindingChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CreateDataBindingViewModels();
|
CreateDataBindingViewModels();
|
||||||
|
SubscribeToSelectedDataBinding();
|
||||||
|
|
||||||
|
SelectedItemIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SubscribeToSelectedDataBinding()
|
||||||
|
{
|
||||||
|
if (_selectedDataBinding != null)
|
||||||
|
{
|
||||||
|
_selectedDataBinding.DataBindingPropertyRegistered -= DataBindingRegistrationsChanged;
|
||||||
|
_selectedDataBinding.DataBindingPropertiesCleared -= DataBindingRegistrationsChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
_selectedDataBinding = _profileEditorService.SelectedDataBinding;
|
||||||
|
if (_selectedDataBinding != null)
|
||||||
|
{
|
||||||
|
_selectedDataBinding.DataBindingPropertyRegistered += DataBindingRegistrationsChanged;
|
||||||
|
_selectedDataBinding.DataBindingPropertiesCleared += DataBindingRegistrationsChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataBindingRegistrationsChanged(object sender, LayerPropertyEventArgs e)
|
||||||
|
{
|
||||||
|
if (_updating)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_updating = true;
|
||||||
|
Execute.PostToUIThread(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(200);
|
||||||
|
CreateDataBindingViewModels();
|
||||||
|
_updating = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Overrides of Screen
|
#region Overrides of Screen
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void OnInitialActivate()
|
protected override void OnInitialActivate()
|
||||||
{
|
{
|
||||||
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
|
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
|
||||||
CreateDataBindingViewModels();
|
CreateDataBindingViewModels();
|
||||||
|
SubscribeToSelectedDataBinding();
|
||||||
base.OnInitialActivate();
|
base.OnInitialActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnActivate()
|
||||||
|
{
|
||||||
|
SelectedItemIndex = 0;
|
||||||
|
base.OnActivate();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnClose()
|
protected override void OnClose()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user