Browse Source

Use SetCurrentValue() in ColorPicker controls

pull/10439/head
robloo 4 years ago
parent
commit
7311ed01b6
  1. 2
      src/Avalonia.Controls.ColorPicker/ColorPreviewer/ColorPreviewer.cs
  2. 12
      src/Avalonia.Controls.ColorPicker/ColorSlider/ColorSlider.cs
  3. 14
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs
  4. 14
      src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs

2
src/Avalonia.Controls.ColorPicker/ColorPreviewer/ColorPreviewer.cs

@ -124,7 +124,7 @@ namespace Avalonia.Controls.Primitives
if (accentStep != 0) if (accentStep != 0)
{ {
// ColorChanged will be invoked in OnPropertyChanged if the value is different // ColorChanged will be invoked in OnPropertyChanged if the value is different
HsvColor = AccentColorConverter.GetAccent(hsvColor, accentStep); SetCurrentValue(HsvColorProperty, AccentColorConverter.GetAccent(hsvColor, accentStep));
} }
} }
} }

12
src/Avalonia.Controls.ColorPicker/ColorSlider/ColorSlider.cs

@ -373,7 +373,7 @@ namespace Avalonia.Controls.Primitives
ignorePropertyChanged = true; ignorePropertyChanged = true;
// Always keep the two color properties in sync // Always keep the two color properties in sync
HsvColor = Color.ToHsv(); SetCurrentValue(HsvColorProperty, Color.ToHsv());
SetColorToSliderValues(); SetColorToSliderValues();
UpdateBackground(); UpdateBackground();
@ -403,7 +403,7 @@ namespace Avalonia.Controls.Primitives
ignorePropertyChanged = true; ignorePropertyChanged = true;
// Always keep the two color properties in sync // Always keep the two color properties in sync
Color = HsvColor.ToRgb(); SetCurrentValue(ColorProperty, HsvColor.ToRgb());
SetColorToSliderValues(); SetColorToSliderValues();
UpdateBackground(); UpdateBackground();
@ -440,13 +440,13 @@ namespace Avalonia.Controls.Primitives
if (ColorModel == ColorModel.Hsva) if (ColorModel == ColorModel.Hsva)
{ {
HsvColor = hsvColor; SetCurrentValue(HsvColorProperty, hsvColor);
Color = hsvColor.ToRgb(); SetCurrentValue(ColorProperty, hsvColor.ToRgb());
} }
else else
{ {
Color = color; SetCurrentValue(ColorProperty, color);
HsvColor = color.ToHsv(); SetCurrentValue(HsvColorProperty, color.ToHsv());
} }
UpdatePseudoClasses(); UpdatePseudoClasses();

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

@ -403,7 +403,7 @@ namespace Avalonia.Controls.Primitives
_updatingHsvColor = true; _updatingHsvColor = true;
Hsv newHsv = (new Rgb(color)).ToHsv(); Hsv newHsv = (new Rgb(color)).ToHsv();
HsvColor = newHsv.ToHsvColor(color.A / 255.0); SetCurrentValue(HsvColorProperty, newHsv.ToHsvColor(color.A / 255.0));
_updatingHsvColor = false; _updatingHsvColor = false;
UpdateEllipse(); UpdateEllipse();
@ -509,15 +509,15 @@ namespace Avalonia.Controls.Primitives
{ {
case ColorSpectrumComponents.HueSaturation: case ColorSpectrumComponents.HueSaturation:
case ColorSpectrumComponents.SaturationHue: case ColorSpectrumComponents.SaturationHue:
ThirdComponent = (ColorComponent)HsvComponent.Value; SetCurrentValue(ThirdComponentProperty, (ColorComponent)HsvComponent.Value);
break; break;
case ColorSpectrumComponents.HueValue: case ColorSpectrumComponents.HueValue:
case ColorSpectrumComponents.ValueHue: case ColorSpectrumComponents.ValueHue:
ThirdComponent = (ColorComponent)HsvComponent.Saturation; SetCurrentValue(ThirdComponentProperty, (ColorComponent)HsvComponent.Saturation);
break; break;
case ColorSpectrumComponents.SaturationValue: case ColorSpectrumComponents.SaturationValue:
case ColorSpectrumComponents.ValueSaturation: case ColorSpectrumComponents.ValueSaturation:
ThirdComponent = (ColorComponent)HsvComponent.Hue; SetCurrentValue(ThirdComponentProperty, (ColorComponent)HsvComponent.Hue);
break; break;
} }
@ -534,7 +534,7 @@ namespace Avalonia.Controls.Primitives
_updatingColor = true; _updatingColor = true;
Rgb newRgb = (new Hsv(hsvColor)).ToRgb(); Rgb newRgb = (new Hsv(hsvColor)).ToRgb();
Color = newRgb.ToColor(hsvColor.A); SetCurrentValue(ColorProperty, newRgb.ToColor(hsvColor.A));
_updatingColor = false; _updatingColor = false;
@ -608,8 +608,8 @@ namespace Avalonia.Controls.Primitives
Rgb newRgb = newHsv.ToRgb(); Rgb newRgb = newHsv.ToRgb();
double alpha = HsvColor.A; double alpha = HsvColor.A;
Color = newRgb.ToColor(alpha); SetCurrentValue(ColorProperty, newRgb.ToColor(alpha));
HsvColor = newHsv.ToHsvColor(alpha); SetCurrentValue(HsvColorProperty, newHsv.ToHsvColor(alpha));
UpdateEllipse(); UpdateEllipse();
UpdatePseudoClasses(); UpdatePseudoClasses();

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

@ -50,7 +50,7 @@ namespace Avalonia.Controls
if (convertedColor is Color color) if (convertedColor is Color color)
{ {
Color = color; SetCurrentValue(ColorProperty, color);
} }
// Re-apply the hex value // Re-apply the hex value
@ -167,7 +167,7 @@ namespace Avalonia.Controls
// The work-around for this is done here where SelectedIndex is forcefully // The work-around for this is done here where SelectedIndex is forcefully
// synchronized with whatever the TabControl property value is. This is // synchronized with whatever the TabControl property value is. This is
// possible since selection validation is already done by this method. // possible since selection validation is already done by this method.
SelectedIndex = _tabControl.SelectedIndex; SetCurrentValue(SelectedIndexProperty, _tabControl.SelectedIndex);
} }
return; return;
@ -211,7 +211,7 @@ namespace Avalonia.Controls
{ {
ignorePropertyChanged = true; ignorePropertyChanged = true;
HsvColor = Color.ToHsv(); SetCurrentValue(HsvColorProperty, Color.ToHsv());
SetColorToHexTextBox(); SetColorToHexTextBox();
OnColorChanged(new ColorChangedEventArgs( OnColorChanged(new ColorChangedEventArgs(
@ -224,7 +224,7 @@ namespace Avalonia.Controls
{ {
ignorePropertyChanged = true; ignorePropertyChanged = true;
Color = HsvColor.ToRgb(); SetCurrentValue(ColorProperty, HsvColor.ToRgb());
SetColorToHexTextBox(); SetColorToHexTextBox();
OnColorChanged(new ColorChangedEventArgs( OnColorChanged(new ColorChangedEventArgs(
@ -241,7 +241,7 @@ namespace Avalonia.Controls
// bound properties controlling the palette grid // bound properties controlling the palette grid
if (palette != null) if (palette != null)
{ {
PaletteColumnCount = palette.ColorCount; SetCurrentValue(PaletteColumnCountProperty, palette.ColorCount);
List<Color> newPaletteColors = new List<Color>(); List<Color> newPaletteColors = new List<Color>();
for (int shadeIndex = 0; shadeIndex < palette.ShadeCount; shadeIndex++) for (int shadeIndex = 0; shadeIndex < palette.ShadeCount; shadeIndex++)
@ -252,14 +252,14 @@ namespace Avalonia.Controls
} }
} }
PaletteColors = newPaletteColors; SetCurrentValue(PaletteColorsProperty, newPaletteColors);
} }
} }
else if (change.Property == IsAlphaEnabledProperty) else if (change.Property == IsAlphaEnabledProperty)
{ {
// Manually coerce the HsvColor value // Manually coerce the HsvColor value
// (Color will be coerced automatically if HsvColor changes) // (Color will be coerced automatically if HsvColor changes)
HsvColor = OnCoerceHsvColor(HsvColor); SetCurrentValue(HsvColorProperty, OnCoerceHsvColor(HsvColor));
} }
else if (change.Property == IsColorComponentsVisibleProperty || else if (change.Property == IsColorComponentsVisibleProperty ||
change.Property == IsColorPaletteVisibleProperty || change.Property == IsColorPaletteVisibleProperty ||

Loading…
Cancel
Save