mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +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>
|
||||
/// <returns>A <see cref="string"/> representation of a color</returns>
|
||||
internal static string GetStringRepresentation(Color color, string colorRepresentationType, string colorFormat)
|
||||
=> colorRepresentationType switch
|
||||
{
|
||||
if (string.IsNullOrEmpty(colorFormat))
|
||||
{
|
||||
"CMYK" => ColorToCMYK(color),
|
||||
"HEX" => ColorToHex(color),
|
||||
"HSB" => ColorToHSB(color),
|
||||
"HSI" => ColorToHSI(color),
|
||||
"HSL" => ColorToHSL(color),
|
||||
"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),
|
||||
};
|
||||
return ColorToHex(color);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ColorFormatHelper.GetStringRepresentation(color, colorFormat);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="string"/> representation of a CMYK color
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using System.Drawing;
|
||||
using ColorPicker.Helpers;
|
||||
using ManagedCommon;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.ColorPicker.UnitTests
|
||||
@@ -29,7 +30,7 @@ namespace Microsoft.ColorPicker.UnitTests
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user