Skip to content

Commit

Permalink
#14020 and #12630 - Show color as a float and as a decimal value
Browse files Browse the repository at this point in the history
  • Loading branch information
Clint Rutkas committed Nov 19, 2021
1 parent 0aaf00d commit 022dde4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/colorPicker/ColorPickerUI/Helpers/ColorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ internal static (double cyan, double magenta, double yellow, double blackKey) Co
return (cyan, magenta, yellow, blackKey);
}

/// <summary>
/// Convert a given <see cref="Color"/> to a float color styling(0.1f, 0.1f, 0.1f)
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The int / 255d for each value to get value between 0 and 1</returns>
internal static (double red, double green, double blue) ConvertToDouble(Color color)
=> (color.R / 255d, color.G / 255d, color.B / 255d);

/// <summary>
/// Convert a given <see cref="Color"/> to a HSB color (hue, saturation, brightness)
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ internal static string GetStringRepresentation(Color color, ColorRepresentationT
ColorRepresentationType.RGB => ColorToRGB(color),
ColorRepresentationType.CIELAB => ColorToCIELAB(color),
ColorRepresentationType.CIEXYZ => ColorToCIEXYZ(color),
ColorRepresentationType.RGBfloat => ColorToFloat(color),
ColorRepresentationType.Decimal => ColorToDecimal(color),

// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
_ => ColorToHex(color),
Expand Down Expand Up @@ -99,6 +101,29 @@ private static string ColorToHSB(Color color)
+ $", {brightness.ToString(CultureInfo.InvariantCulture)}%)";
}

/// <summary>
/// Return a <see cref="string"/> representation float color styling(0.1f, 0.1f, 0.1f)
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>a string value (0.1f, 0.1f, 0.1f)</returns>
private static string ColorToFloat(Color color)
{
var (red, green, blue) = ColorHelper.ConvertToDouble(color);
var precison = 2;

return $"({Math.Round(red, precison)}f, {Math.Round(green, precison)}f, {Math.Round(blue, precison)}f, 1)";
}

/// <summary>
/// Return a <see cref="string"/> representation decimal color value
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>a string value number</returns>
private static string ColorToDecimal(Color color)
{
return $"{color.R + (color.G * 256) + (color.B * 65536)}";
}

/// <summary>
/// Return a <see cref="string"/> representation of a HSI color
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ private void SetupAllColorRepresentations()
FormatName = ColorRepresentationType.CIEXYZ.ToString(),
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CIEXYZ); },
});
_allColorRepresentations.Add(
new ColorFormatModel()
{
FormatName = ColorRepresentationType.RGBfloat.ToString(),
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.RGBfloat); },
});
_allColorRepresentations.Add(
new ColorFormatModel()
{
FormatName = ColorRepresentationType.Decimal.ToString(),
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.Decimal); },
});

_userSettings.VisibleColorFormats.CollectionChanged += VisibleColorFormats_CollectionChanged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ColorRepresentationHelperTest
[DataRow(ColorRepresentationType.RGB, "rgb(0, 0, 0)")]
[DataRow(ColorRepresentationType.CIELAB, "CIELab(0, 0, 0)")]
[DataRow(ColorRepresentationType.CIEXYZ, "xyz(0, 0, 0)")]
[DataRow(ColorRepresentationType.RGBfloat, "(0.00f, 0.00f, 0.00f, 1)")]
[DataRow(ColorRepresentationType.Decimal, "0")]

public void GetStringRepresentationTest(ColorRepresentationType type, string expected)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,17 @@ public enum ColorRepresentationType
/// Color presentation as CIEXYZ color space (X[0..95], Y[0..100], Z[0..109]
/// </summary>
CIEXYZ = 10,

/// <summary>
/// Color presentation as RGB float (red[0..1], green[0..1], blue[0..1])
/// </summary>
RGBfloat = 11,

/// <summary>
/// Color presentation as integer decimal value 0-16777215
/// </summary>
#pragma warning disable CA1720 // Identifier contains type name
Decimal = 12,
#pragma warning restore CA1720 // Identifier contains type name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public ColorPickerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<Ge
{ ColorRepresentationType.RGB, "RGB - rgb(100, 50, 75)" },
{ ColorRepresentationType.CIELAB, "CIE LAB - CIELab(76, 21, 80)" },
{ ColorRepresentationType.CIEXYZ, "CIE XYZ - xyz(56, 50, 7)" },
{ ColorRepresentationType.RGBfloat, "(1.0f, 0.7f, 0.00f)" },
{ ColorRepresentationType.Decimal, "16755200" },
};

GeneralSettingsConfig = settingsRepository.SettingsConfig;
Expand Down Expand Up @@ -198,6 +200,8 @@ private void InitializeColorFormats()
var ncolFormatName = ColorRepresentationType.NCol.ToString();
var cielabFormatName = ColorRepresentationType.CIELAB.ToString();
var ciexyzFormatName = ColorRepresentationType.CIEXYZ.ToString();
var rgbFloatFormatName = ColorRepresentationType.RGBfloat.ToString();
var decimalFormatName = ColorRepresentationType.Decimal.ToString();

formatsUnordered.Add(new ColorFormatModel(hexFormatName, "ef68ff", visibleFormats.ContainsKey(hexFormatName) && visibleFormats[hexFormatName]));
formatsUnordered.Add(new ColorFormatModel(rgbFormatName, "rgb(239, 104, 255)", visibleFormats.ContainsKey(rgbFormatName) && visibleFormats[rgbFormatName]));
Expand All @@ -210,6 +214,8 @@ private void InitializeColorFormats()
formatsUnordered.Add(new ColorFormatModel(ncolFormatName, "R10, 50%, 75%", visibleFormats.ContainsKey(ncolFormatName) && visibleFormats[ncolFormatName]));
formatsUnordered.Add(new ColorFormatModel(cielabFormatName, "CIELab(66, 72, -52)", visibleFormats.ContainsKey(cielabFormatName) && visibleFormats[cielabFormatName]));
formatsUnordered.Add(new ColorFormatModel(ciexyzFormatName, "xyz(59, 35, 98)", visibleFormats.ContainsKey(ciexyzFormatName) && visibleFormats[ciexyzFormatName]));
formatsUnordered.Add(new ColorFormatModel(rgbFloatFormatName, "(0.94f, 0.41f, 1.00f, 1)", visibleFormats.ContainsKey(rgbFloatFormatName) && visibleFormats[rgbFloatFormatName]));
formatsUnordered.Add(new ColorFormatModel(decimalFormatName, "15689983", visibleFormats.ContainsKey(decimalFormatName) && visibleFormats[decimalFormatName]));

foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
{
Expand Down

2 comments on commit 022dde4

@github-actions
Copy link

@github-actions github-actions bot commented on 022dde4 Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

Unrecognized words, please review:

  • Bfloat
  • precison
Previously acknowledged words that are now absent Accessible Actioncenter Addavirtualdesktop ALIGNLEFT AUTOAPPEND AUTOSIZECOLUMNS available BEGINLABELEDIT btn Captureascreenshot CASESENSITIVE checkboxes CHECKCANCELED chrisharris CIEXYZ coc COLUMNCLICK Connectquickaction coords countslabelrenamingfmt countslabelselectedfmt CRename CTriage dchristensen DISPINFO Displayandhidethedesktop djsoref docsmsft dogancelik DOUBLEBUFFER dupenv DWLP Easeof Entireitemname ENUMITEMS estdir EXCLUDEFILES EXCLUDEFOLDERS EXCLUDESUBFOLDERS EXISTINGIMAGERESIZERPATH EXISTINGPOWERRENAMEEXTPATH EXTENIONONLY EXTENSIONONLY FFAA Fody ftp ftps FULLNAME Gamebar GETDISPINFO GETEMPTYMARKUP gmx HACCEL HDF hdi HDITEM hdlg HDN HDS hitinfo htt ianjoneill IAuto IDrop INDEXTOSTATEIMAGEMASK inprivate installpowertoys IPreview IProgress ITEMSTATEICONCLICK IThumbnail itsme jakeoeding KERNELBASE linecap Linkmenu listbox Lockyour LPDWORD LPNMHDR LPNMHEADER LPNMLISTVIEW LPOLESTR LPPOINT lvc LVCF LVCFMT LVHITTESTINFO LVHT LVIF LVIS LVN LVS LVSIL MARQUEEPROGRESS MATCHALLOCCURENCES MATCHMODE mfreadwrite mfuuid Minimizeallwindows MINMAXINFO NAMEONLY Nefario nitroin NMLVEMPTYMARKUP noactive Noactivewindow null nunit ONITEM Openthe OPTIONSGROUP pcelt PCorswitchaccounts pitem plvdi pnm pnmdr pnmlv POINTL polymorpism powertoyswiki ppenum ppsrui PREVIEWGROUP PROGDLG prpui Prt prui Radiobuttons rdeveen RDW refcount REPLACEWITH Reportx rgelt Rgn Rundialogbox Scn SEARCHFOR SEARCHREPLACEGROUP SHAREIMAGELISTS sidepanel SINGLESEL SORTDOWN spamming spdth sppd sppre spsrif spsrui STATEIMAGEMASK Switchbetweenvirtualdesktops systray Taskview Temporarilypeekatthedesktop THEMECHANGED TIMERID titlecase ulazy UPDOWNKEYDROPSLIST USEREGEX windevbuildagents winstore XDiff xia XSmall xunit YDiff Zoomusingmagnifier
Some files were were automatically ignored

These sample patterns would exclude them:

^src/modules/previewpane/UnitTests-MarkdownPreviewHandler/HelperFiles/MarkdownWithHTMLImageTag\.txt$

You should consider adding them to:

.github/actions/spell-check/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:microsoft/PowerToys.git repository
on the main branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
(cat '.github/actions/spell-check/excludes.txt' - <<EOF
$should_exclude_patterns
EOF
) |grep .|
sort -f |
uniq > '.github/actions/spell-check/excludes.txt.temp' &&
mv '.github/actions/spell-check/excludes.txt.temp' '.github/actions/spell-check/excludes.txt'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/PowerToys/comments/60585002" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  

should_exclude_patterns=$(perl -e '$/=undef;
$_=<>;
exit unless s{(?:You should consider excluding directory paths|You should consider adding them to).*}{}s;
s{.*These sample patterns would exclude them:}{}s;
s{.*\`\`\`([^`]*)\`\`\`.*}{$1}m;
print' < "$comment_body" | grep . || true)

update_files
rm $comment_body
git add -u
If you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to the patterns.txt file.

Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

Note that patterns can't match multiline strings.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

@github-actions
Copy link

@github-actions github-actions bot commented on 022dde4 Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

Unrecognized words, please review:

  • Bfloat
  • precison
Previously acknowledged words that are now absent Accessible Actioncenter Addavirtualdesktop ALIGNLEFT AUTOAPPEND AUTOSIZECOLUMNS available BEGINLABELEDIT btn Captureascreenshot CASESENSITIVE checkboxes CHECKCANCELED chrisharris CIEXYZ coc COLUMNCLICK Connectquickaction coords countslabelrenamingfmt countslabelselectedfmt CRename CTriage dchristensen DISPINFO Displayandhidethedesktop djsoref docsmsft dogancelik DOUBLEBUFFER dupenv DWLP Easeof Entireitemname ENUMITEMS estdir EXCLUDEFILES EXCLUDEFOLDERS EXCLUDESUBFOLDERS EXISTINGIMAGERESIZERPATH EXISTINGPOWERRENAMEEXTPATH EXTENIONONLY EXTENSIONONLY FFAA Fody ftp ftps FULLNAME Gamebar GETDISPINFO GETEMPTYMARKUP gmx HACCEL HDF hdi HDITEM hdlg HDN HDS hitinfo htt ianjoneill IAuto IDrop INDEXTOSTATEIMAGEMASK inprivate installpowertoys IPreview IProgress ITEMSTATEICONCLICK IThumbnail itsme jakeoeding KERNELBASE linecap Linkmenu listbox Lockyour LPDWORD LPNMHDR LPNMHEADER LPNMLISTVIEW LPOLESTR LPPOINT lvc LVCF LVCFMT LVHITTESTINFO LVHT LVIF LVIS LVN LVS LVSIL MARQUEEPROGRESS MATCHALLOCCURENCES MATCHMODE mfreadwrite mfuuid Minimizeallwindows MINMAXINFO NAMEONLY Nefario nitroin NMLVEMPTYMARKUP noactive Noactivewindow null nunit ONITEM Openthe OPTIONSGROUP pcelt PCorswitchaccounts pitem plvdi pnm pnmdr pnmlv POINTL polymorpism powertoyswiki ppenum ppsrui PREVIEWGROUP PROGDLG prpui Prt prui Radiobuttons rdeveen RDW refcount REPLACEWITH Reportx rgelt Rgn Rundialogbox Scn SEARCHFOR SEARCHREPLACEGROUP SHAREIMAGELISTS sidepanel SINGLESEL SORTDOWN spamming spdth sppd sppre spsrif spsrui STATEIMAGEMASK Switchbetweenvirtualdesktops systray Taskview Temporarilypeekatthedesktop THEMECHANGED TIMERID titlecase ulazy UPDOWNKEYDROPSLIST USEREGEX windevbuildagents winstore XDiff xia XSmall xunit YDiff Zoomusingmagnifier
Some files were were automatically ignored

These sample patterns would exclude them:

^src/modules/previewpane/UnitTests-MarkdownPreviewHandler/HelperFiles/MarkdownWithHTMLImageTag\.txt$

You should consider adding them to:

.github/actions/spell-check/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:microsoft/PowerToys.git repository
on the dev/crutkas/newColorPicker branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
(cat '.github/actions/spell-check/excludes.txt' - <<EOF
$should_exclude_patterns
EOF
) |grep .|
sort -f |
uniq > '.github/actions/spell-check/excludes.txt.temp' &&
mv '.github/actions/spell-check/excludes.txt.temp' '.github/actions/spell-check/excludes.txt'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/PowerToys/comments/60585125" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  

should_exclude_patterns=$(perl -e '$/=undef;
$_=<>;
exit unless s{(?:You should consider excluding directory paths|You should consider adding them to).*}{}s;
s{.*These sample patterns would exclude them:}{}s;
s{.*\`\`\`([^`]*)\`\`\`.*}{$1}m;
print' < "$comment_body" | grep . || true)

update_files
rm $comment_body
git add -u
If you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to the patterns.txt file.

Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

Note that patterns can't match multiline strings.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

Please sign in to comment.