mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[ColorPicker]Use the new custom formats when picking colors without editor (#22552)
* ColorPicker fixing 'old' formats still represented in the old pre-defined format in color picker module. * Fixing color picker tests, adding format strings
This commit is contained in:
@@ -34,26 +34,16 @@ namespace ColorPicker.Helpers
|
|||||||
/// <param name="colorRepresentationType">The type of the representation</param>
|
/// <param name="colorRepresentationType">The type of the representation</param>
|
||||||
/// <returns>A <see cref="string"/> representation of a color</returns>
|
/// <returns>A <see cref="string"/> representation of a color</returns>
|
||||||
internal static string GetStringRepresentation(Color color, string colorRepresentationType, string colorFormat)
|
internal static string GetStringRepresentation(Color color, string colorRepresentationType, string colorFormat)
|
||||||
=> colorRepresentationType switch
|
{
|
||||||
|
if (string.IsNullOrEmpty(colorFormat))
|
||||||
{
|
{
|
||||||
"CMYK" => ColorToCMYK(color),
|
return ColorToHex(color);
|
||||||
"HEX" => ColorToHex(color),
|
}
|
||||||
"HSB" => ColorToHSB(color),
|
else
|
||||||
"HSI" => ColorToHSI(color),
|
{
|
||||||
"HSL" => ColorToHSL(color),
|
return ColorFormatHelper.GetStringRepresentation(color, colorFormat);
|
||||||
"HSV" => ColorToHSV(color),
|
}
|
||||||
"HWB" => ColorToHWB(color),
|
}
|
||||||
"NCol" => ColorToNCol(color),
|
|
||||||
"RGB" => ColorToRGB(color),
|
|
||||||
"CIELAB" => ColorToCIELAB(color),
|
|
||||||
"CIEXYZ" => ColorToCIEXYZ(color),
|
|
||||||
"VEC4" => ColorToFloat(color),
|
|
||||||
"Decimal" => ColorToDecimal(color),
|
|
||||||
"HEX Int" => ColorToHexInteger(color),
|
|
||||||
|
|
||||||
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
|
|
||||||
_ => string.IsNullOrEmpty(colorFormat) ? ColorToHex(color) : ColorFormatHelper.GetStringRepresentation(color, colorFormat),
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a <see cref="string"/> representation of a CMYK color
|
/// Return a <see cref="string"/> representation of a CMYK color
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using ColorPicker.Helpers;
|
using ColorPicker.Helpers;
|
||||||
|
using ManagedCommon;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace Microsoft.ColorPicker.UnitTests
|
namespace Microsoft.ColorPicker.UnitTests
|
||||||
@@ -29,7 +30,7 @@ namespace Microsoft.ColorPicker.UnitTests
|
|||||||
|
|
||||||
public void GetStringRepresentationTest(string type, string expected)
|
public void GetStringRepresentationTest(string type, string expected)
|
||||||
{
|
{
|
||||||
var result = ColorRepresentationHelper.GetStringRepresentation(Color.Black, type, string.Empty);
|
var result = ColorRepresentationHelper.GetStringRepresentation(Color.Black, type, ColorFormatHelper.GetDefaultFormat(type));
|
||||||
Assert.AreEqual(result, expected);
|
Assert.AreEqual(result, expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user