diff --git a/src/common/ManagedCommon/ColorFormatHelper.cs b/src/common/ManagedCommon/ColorFormatHelper.cs index 471104f215..d353e52018 100644 --- a/src/common/ManagedCommon/ColorFormatHelper.cs +++ b/src/common/ManagedCommon/ColorFormatHelper.cs @@ -515,8 +515,7 @@ namespace ManagedCommon return lightnessL.ToString(CultureInfo.InvariantCulture); case "Lc": var (lightnessC, _, _) = ConvertToCIELABColor(color); - lightnessC = Math.Round(lightnessC, 2); - return lightnessC.ToString(CultureInfo.InvariantCulture); + return ColorPercentFormatted(lightnessC, paramFormat, 2); case "Lo": var (lightnessO, _, _) = ConvertToOklabColor(color); lightnessO = Math.Round(lightnessO, 2); @@ -531,12 +530,10 @@ namespace ManagedCommon return blackness.ToString(CultureInfo.InvariantCulture); case "Ca": var (_, chromaticityA, _) = ConvertToCIELABColor(color); - chromaticityA = Math.Round(chromaticityA, 2); - return chromaticityA.ToString(CultureInfo.InvariantCulture); + return ColorPercentFormatted(chromaticityA, paramFormat, 2); case "Cb": var (_, _, chromaticityB) = ConvertToCIELABColor(color); - chromaticityB = Math.Round(chromaticityB, 2); - return chromaticityB.ToString(CultureInfo.InvariantCulture); + return ColorPercentFormatted(chromaticityB, paramFormat, 2); case "Oa": var (_, chromaticityAOklab, _) = ConvertToOklabColor(color); chromaticityAOklab = Math.Round(chromaticityAOklab, 2); @@ -595,6 +592,24 @@ namespace ManagedCommon } } + private static string ColorPercentFormatted(double colorPercentValue, char paramFormat, int defaultDecimalDigits) + { + switch (paramFormat) + { + case 'i': + double roundedColorPercentValue = Math.Round(colorPercentValue); + if (roundedColorPercentValue == 0) + { + // convert -0 to 0 + roundedColorPercentValue = 0.0; + } + + return roundedColorPercentValue.ToString(CultureInfo.InvariantCulture); + default: + return Math.Round(colorPercentValue, defaultDecimalDigits).ToString(CultureInfo.InvariantCulture); + } + } + public static string GetDefaultFormat(string formatName) { switch (formatName) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml index 743ced3204..c42693107f 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml @@ -108,7 +108,7 @@ Style="{StaticResource CaptionTextBlockStyle}" /> @@ -117,6 +117,18 @@ x:Uid="ColorFormatEditorHelpline3" VerticalAlignment="Bottom" Style="{StaticResource CaptionTextBlockStyle}" /> + + + + + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml.cs index 475d399674..cf505a4817 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml.cs @@ -66,7 +66,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls new ColorFormatParameter() { Parameter = "%Na", Description = resourceLoader.GetString("Help_color_name") }, }; - ColorParametersItemsControl.ItemsSource = new List + RGBAColorParametersItemsControl.ItemsSource = new List { new ColorFormatParameter() { Parameter = "b", Description = resourceLoader.GetString("Help_byte") }, new ColorFormatParameter() { Parameter = "h", Description = resourceLoader.GetString("Help_hexL1") }, @@ -76,6 +76,11 @@ namespace Microsoft.PowerToys.Settings.UI.Controls new ColorFormatParameter() { Parameter = "f", Description = resourceLoader.GetString("Help_floatWith") }, new ColorFormatParameter() { Parameter = "F", Description = resourceLoader.GetString("Help_floatWithout") }, }; + + CIELabColorParametersItemsControl.ItemsSource = new List + { + new ColorFormatParameter() { Parameter = "i", Description = resourceLoader.GetString("Help_integer") }, + }; } private void NewColorName_TextChanged(object sender, TextChangedEventArgs e) diff --git a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw index 7315147ddb..6b2fd3646f 100644 --- a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw @@ -1727,7 +1727,13 @@ Made with 💗 by Microsoft and the PowerToys community. float without leading zero - + + The lightness (CIE), chromaticity A (CIE Lab) and chromaticity B (CIE Lab) values can be formatted to the following formats: + + + rounded to the nearest integer + + Example: %ReX means red value in hex uppercase two digits format.