Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/common/ManagedCommon/ColorFormatHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,7 @@ private static string GetStringRepresentation(Color color, char paramFormat, str
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);
Expand All @@ -531,12 +530,10 @@ private static string GetStringRepresentation(Color color, char paramFormat, str
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);
Expand Down Expand Up @@ -595,6 +592,24 @@ private static string ColorByteFormatted(byte colorByteValue, char paramFormat)
}
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
Style="{StaticResource CaptionTextBlockStyle}" />

<ItemsControl
x:Name="ColorParametersItemsControl"
x:Name="RGBAColorParametersItemsControl"
IsTabStop="False"
ItemTemplate="{StaticResource ColorParameterTemplate}"
ItemsPanel="{StaticResource ItemPanelTemplate}" />
Expand All @@ -117,6 +117,18 @@
x:Uid="ColorFormatEditorHelpline3"
VerticalAlignment="Bottom"
Style="{StaticResource CaptionTextBlockStyle}" />

<ItemsControl
x:Name="CIELabColorParametersItemsControl"
IsTabStop="False"
ItemTemplate="{StaticResource ColorParameterTemplate}"
ItemsPanel="{StaticResource ItemPanelTemplate}" />

<TextBlock
x:Uid="ColorFormatEditorHelpline4"
VerticalAlignment="Bottom"
Style="{StaticResource CaptionTextBlockStyle}" />

</StackPanel>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void LoadParameters()
new ColorFormatParameter() { Parameter = "%Na", Description = resourceLoader.GetString("Help_color_name") },
};

ColorParametersItemsControl.ItemsSource = new List<ColorFormatParameter>
RGBAColorParametersItemsControl.ItemsSource = new List<ColorFormatParameter>
{
new ColorFormatParameter() { Parameter = "b", Description = resourceLoader.GetString("Help_byte") },
new ColorFormatParameter() { Parameter = "h", Description = resourceLoader.GetString("Help_hexL1") },
Expand All @@ -76,6 +76,11 @@ public void LoadParameters()
new ColorFormatParameter() { Parameter = "f", Description = resourceLoader.GetString("Help_floatWith") },
new ColorFormatParameter() { Parameter = "F", Description = resourceLoader.GetString("Help_floatWithout") },
};

CIELabColorParametersItemsControl.ItemsSource = new List<ColorFormatParameter>
{
new ColorFormatParameter() { Parameter = "i", Description = resourceLoader.GetString("Help_integer") },
};
}

private void NewColorName_TextChanged(object sender, TextChangedEventArgs e)
Expand Down
8 changes: 7 additions & 1 deletion src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,13 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
<data name="Help_floatWithout" xml:space="preserve">
<value>float without leading zero</value>
</data>
<data name="ColorFormatEditorHelpline3.Text" xml:space="preserve">
<data name="ColorFormatEditorHelpline3.Text" xml:space="preserve">
<value>The lightness (CIE), chromaticity A (CIE Lab) and chromaticity B (CIE Lab) values can be formatted to the following formats:</value>
</data>
<data name="Help_integer" xml:space="preserve">
<value>rounded to the nearest integer</value>
</data>
<data name="ColorFormatEditorHelpline4.Text" xml:space="preserve">
<value>Example: %ReX means red value in hex uppercase two digits format.</value>
</data>
<data name="ColorPicker_ShowColorName.Header" xml:space="preserve">
Expand Down