mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Gradient picker button - Always update gradient on UI thread
Data bindings - Added AlwaysApplyDataBindings setting
This commit is contained in:
parent
29ef160975
commit
f09b4a20bf
@ -10,6 +10,7 @@ using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using FluentAvalonia.Core;
|
||||
using Button = FluentAvalonia.UI.Controls.Button;
|
||||
|
||||
@ -138,12 +139,12 @@ public class GradientPickerButton : TemplatedControl
|
||||
|
||||
private void ColorGradientOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
UpdateGradient();
|
||||
Dispatcher.UIThread.Post(UpdateGradient);
|
||||
}
|
||||
|
||||
private void ColorGradientOnStopChanged(object? sender, EventArgs e)
|
||||
{
|
||||
UpdateGradient();
|
||||
Dispatcher.UIThread.Post(UpdateGradient);
|
||||
}
|
||||
|
||||
private void OnButtonClick(object? sender, RoutedEventArgs e)
|
||||
|
||||
@ -6,8 +6,6 @@ using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
using System.Reactive.Linq;
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.VisualScripting;
|
||||
@ -8,7 +12,7 @@ using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor.Commands;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Properties.DataBinding;
|
||||
@ -17,14 +21,17 @@ public class DataBindingViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly PluginSetting<bool> _alwaysApplyDataBindings;
|
||||
private ObservableAsPropertyHelper<bool>? _dataBindingEnabled;
|
||||
private ObservableAsPropertyHelper<ILayerProperty?>? _layerProperty;
|
||||
private ObservableAsPropertyHelper<NodeScriptViewModel?>? _nodeScriptViewModel;
|
||||
private bool _playing;
|
||||
|
||||
public DataBindingViewModel(IProfileEditorService profileEditorService, INodeVmFactory nodeVmFactory, IWindowService windowService)
|
||||
public DataBindingViewModel(IProfileEditorService profileEditorService, INodeVmFactory nodeVmFactory, IWindowService windowService, ISettingsService settingsService)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_windowService = windowService;
|
||||
_alwaysApplyDataBindings = settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", false);
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
@ -41,6 +48,11 @@ public class DataBindingViewModel : ActivatableViewModelBase
|
||||
.Select(b => b.IsEnabled)
|
||||
.ToProperty(this, vm => vm.DataBindingEnabled)
|
||||
.DisposeWith(d);
|
||||
_profileEditorService.Playing.CombineLatest(_profileEditorService.SuspendedEditing).Subscribe(tuple => _playing = tuple.First || tuple.Second).DisposeWith(d);
|
||||
|
||||
DispatcherTimer updateTimer = new(TimeSpan.FromMilliseconds(60.0 / 1000), DispatcherPriority.Render, Update);
|
||||
updateTimer.Start();
|
||||
Disposable.Create(() => updateTimer.Stop()).DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
@ -62,4 +74,13 @@ public class DataBindingViewModel : ActivatableViewModelBase
|
||||
if (LayerProperty != null && LayerProperty.BaseDataBinding.IsEnabled)
|
||||
await _windowService.ShowDialogAsync<NodeScriptWindowViewModel, bool>(("nodeScript", LayerProperty.BaseDataBinding.Script));
|
||||
}
|
||||
|
||||
private void Update(object? sender, EventArgs e)
|
||||
{
|
||||
// If playing the data binding will already be updated, no need to do it here
|
||||
if (_playing || !_alwaysApplyDataBindings.Value)
|
||||
return;
|
||||
|
||||
LayerProperty?.UpdateDataBinding();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user