mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Gradient editor - WIP commit
This commit is contained in:
1 parent
19eb9c3275
commit
81ec5bfe8f
21 files changed
+315
-322
No files matched your search
@@ -0,0 +1,46 @@
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
{
|
||||
public class GradientEditorViewModel : Screen
|
||||
{
|
||||
public GradientEditorViewModel(ColorGradient colorGradient)
|
||||
{
|
||||
ColorGradient = colorGradient;
|
||||
ColorStopViewModels = new BindableCollection<ColorStopViewModel>();
|
||||
|
||||
ColorGradient.PropertyChanged += ColorGradientOnPropertyChanged;
|
||||
UpdateColorStopViewModels();
|
||||
}
|
||||
|
||||
public BindableCollection<ColorStopViewModel> ColorStopViewModels { get; set; }
|
||||
|
||||
public ColorGradient ColorGradient { get; }
|
||||
public double PreviewWidth => 440;
|
||||
|
||||
private void ColorGradientOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(ColorGradient.Stops))
|
||||
UpdateColorStopViewModels();
|
||||
}
|
||||
|
||||
private void UpdateColorStopViewModels()
|
||||
{
|
||||
while (ColorGradient.Stops.Count > ColorStopViewModels.Count)
|
||||
ColorStopViewModels.Add(new ColorStopViewModel(this));
|
||||
while (ColorGradient.Stops.Count < ColorStopViewModels.Count)
|
||||
ColorStopViewModels.RemoveAt(0);
|
||||
|
||||
var index = 0;
|
||||
foreach (var colorStop in ColorGradient.Stops.OrderBy(s => s.Position))
|
||||
{
|
||||
var viewModel = ColorStopViewModels[index];
|
||||
viewModel.Update(colorStop);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user