Browse Source

Switch ColorSpectrum.ThirdComponent to a read-only DirectProperty

pull/10439/head
robloo 4 years ago
parent
commit
bb8e3ae9ab
  1. 4
      src/Avalonia.Controls.ColorPicker/ColorPicker/ColorPicker.cs
  2. 10
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.Properties.cs
  3. 9
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs
  4. 3
      src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs
  5. 2
      src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs

4
src/Avalonia.Controls.ColorPicker/ColorPicker/ColorPicker.cs

@ -1,6 +1,4 @@
using Avalonia.Controls.Primitives;
namespace Avalonia.Controls
namespace Avalonia.Controls
{
/// <summary>
/// Presents a color for user editing using a spectrum, palette and component sliders within a drop down.

10
src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.Properties.cs

@ -96,10 +96,10 @@ namespace Avalonia.Controls.Primitives
/// <summary>
/// Defines the <see cref="ThirdComponent"/> property.
/// </summary>
public static readonly StyledProperty<ColorComponent> ThirdComponentProperty =
AvaloniaProperty.Register<ColorSpectrum, ColorComponent>(
public static readonly DirectProperty<ColorSpectrum, ColorComponent> ThirdComponentProperty =
AvaloniaProperty.RegisterDirect<ColorSpectrum, ColorComponent>(
nameof(ThirdComponent),
ColorComponent.Component3); // Value
o => o.ThirdComponent);
/// <summary>
/// Gets or sets the currently selected color in the RGB color model.
@ -239,8 +239,8 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
public ColorComponent ThirdComponent
{
get => GetValue(ThirdComponentProperty);
protected set => SetValue(ThirdComponentProperty, value);
get => _thirdComponent;
private set => SetAndRaise(ThirdComponentProperty, ref _thirdComponent, value);
}
}
}

9
src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs

@ -13,9 +13,9 @@ using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Reactive;
using Avalonia.Threading;
using Avalonia.Utilities;
using Avalonia.Reactive;
namespace Avalonia.Controls.Primitives
{
@ -48,6 +48,7 @@ namespace Avalonia.Controls.Primitives
private bool _isPointerPressed = false;
private bool _shouldShowLargeSelection = false;
private List<Hsv> _hsvValues = new List<Hsv>();
private ColorComponent _thirdComponent = ColorComponent.Component3; // HsvComponent.Value
private IDisposable? _layoutRootDisposable;
private IDisposable? _selectionEllipsePanelDisposable;
@ -509,15 +510,15 @@ namespace Avalonia.Controls.Primitives
{
case ColorSpectrumComponents.HueSaturation:
case ColorSpectrumComponents.SaturationHue:
SetCurrentValue(ThirdComponentProperty, (ColorComponent)HsvComponent.Value);
ThirdComponent = (ColorComponent)HsvComponent.Value;
break;
case ColorSpectrumComponents.HueValue:
case ColorSpectrumComponents.ValueHue:
SetCurrentValue(ThirdComponentProperty, (ColorComponent)HsvComponent.Saturation);
ThirdComponent = (ColorComponent)HsvComponent.Saturation;
break;
case ColorSpectrumComponents.SaturationValue:
case ColorSpectrumComponents.ValueSaturation:
SetCurrentValue(ThirdComponentProperty, (ColorComponent)HsvComponent.Hue);
ThirdComponent = (ColorComponent)HsvComponent.Hue;
break;
}

3
src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs

@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using Avalonia.Controls.Converters;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
using Avalonia.Threading;
using Avalonia.VisualTree;
namespace Avalonia.Controls
{

2
src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs

@ -4,8 +4,6 @@
// Licensed to The Avalonia Project under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Avalonia.Layout;

Loading…
Cancel
Save