Browse Source

Merge pull request #11650 from robloo/colorpicker-fixes

ColorPicker Fixes
pull/11674/head
Max Katz 3 years ago
committed by GitHub
parent
commit
324d3d3cb0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      src/Avalonia.Controls.ColorPicker/ColorPalettes/FlatColorPalette.cs
  2. 18
      src/Avalonia.Controls.ColorPicker/ColorSpectrum/ColorSpectrum.cs

40
src/Avalonia.Controls.ColorPicker/ColorPalettes/FlatColorPalette.cs

@ -266,26 +266,26 @@ namespace Avalonia.Controls
MidnightBlue9 = 0xFF1C2833,
MidnightBlue10 = 0xFF17202A,
Pomegranate = Pomegranate3,
Alizarin = Alizarin3,
Amethyst = Amethyst3,
Wisteria = Wisteria3,
BelizeHole = BelizeHole3,
PeterRiver = PeterRiver3,
Turquoise = Turquoise3,
GreenSea = GreenSea3,
Nephritis = Nephritis3,
Emerald = Emerald3,
Sunflower = Sunflower3,
Orange = Orange3,
Carrot = Carrot3,
Pumpkin = Pumpkin3,
Clouds = Clouds3,
Silver = Silver3,
Concrete = Concrete3,
Asbestos = Asbestos3,
WetAsphalt = WetAsphalt3,
MidnightBlue = MidnightBlue3,
Pomegranate = Pomegranate6,
Alizarin = Alizarin6,
Amethyst = Amethyst6,
Wisteria = Wisteria6,
BelizeHole = BelizeHole6,
PeterRiver = PeterRiver6,
Turquoise = Turquoise6,
GreenSea = GreenSea6,
Nephritis = Nephritis6,
Emerald = Emerald6,
Sunflower = Sunflower6,
Orange = Orange6,
Carrot = Carrot6,
Pumpkin = Pumpkin6,
Clouds = Clouds6,
Silver = Silver6,
Concrete = Concrete6,
Asbestos = Asbestos6,
WetAsphalt = WetAsphalt6,
MidnightBlue = MidnightBlue6,
};
// See: https://htmlcolorcodes.com/assets/downloads/flat-design-colors/flat-design-color-chart.png

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

@ -45,7 +45,6 @@ namespace Avalonia.Controls.Primitives
private bool _updatingColor = false;
private bool _updatingHsvColor = false;
private bool _coercedInitialColor = false;
private bool _isPointerPressed = false;
private bool _shouldShowLargeSelection = false;
private List<Hsv> _hsvValues = new List<Hsv>();
@ -622,7 +621,7 @@ namespace Avalonia.Controls.Primitives
// that no color has been selected by the user. Note that #00000000 is different than
// #00FFFFFF (Transparent).
//
// In this situation, the first time the user clicks on the spectrum the third
// In this situation, whenever the user clicks on the spectrum, the third
// component and alpha component will remain zero. This is because the spectrum only
// controls two components at any given time.
//
@ -633,16 +632,19 @@ namespace Avalonia.Controls.Primitives
// though the desired value is simply full color.
//
// To work around this usability issue with an initial #00000000 color, the selected
// color is coerced (only the first time) into a color with maximum third component
// value and maximum alpha. This can only happen once and only if those two components
// are already zero.
// color is coerced into a color with maximum third component value and maximum alpha.
// This can only happen here in the spectrum if those two components are already zero.
//
// In the past this coercion was restricted to occur only one time. However, when
// ColorPicker controls are re-used or recycled #00000000 can be set multiple times.
// Each time needs this special logic for usability so now anytime the color is
// changed on the spectrum this logic will run.
//
// Also note this is NOT currently done for #00FFFFFF (Transparent) but based on
// further usability study that case may need to be handled here as well. Right now
// Transparent is treated as a normal color value with the alpha intentionally set
// to zero so the alpha slider must still be adjusted after the spectrum.
if (!_coercedInitialColor &&
IsLoaded)
if (IsLoaded)
{
bool isAlphaComponentZero = (alpha == 0.0);
bool isThirdComponentZero = false;
@ -691,8 +693,6 @@ namespace Avalonia.Controls.Primitives
newHsv.H = 360.0;
break;
}
_coercedInitialColor = true;
}
}

Loading…
Cancel
Save