Skip to content

Commit acda1c3

Browse files
authored
Merge pull request #746 from Avid29/ColorAnalyzer/Palettes
Refactor AccentAnalyzer into ColorPaletteSampler
2 parents c068626 + 80c32b1 commit acda1c3

25 files changed

+440
-383
lines changed

components/ColorAnalyzer/samples/ColorAnalyzer.Samples.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1919
</Content>
2020
</ItemGroup>
21+
<ItemGroup>
22+
<Folder Include="ContrastHelper\" />
23+
</ItemGroup>
2124
</Project>

components/ColorAnalyzer/samples/AccentAnalyzerSample.xaml renamed to components/ColorAnalyzer/samples/ColorPaletteSampler/AccentAnalyzerSample.xaml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
22
<Page x:Class="ColorAnalyzerExperiment.Samples.AccentAnalyzerSample"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -11,10 +11,21 @@
1111
mc:Ignorable="d">
1212

1313
<Page.Resources>
14-
<helpers:AccentAnalyzer x:Name="AccentAnalyzer"
15-
Source="{x:Bind AccentedImage}" />
14+
<helpers:ColorPaletteSampler x:Name="ColorPaletteSampler"
15+
Source="{x:Bind SampledImage}">
16+
<helpers:AccentColorPaletteSelector x:Name="AccentPalette"
17+
MinColorCount="3" />
18+
<helpers:ColorWeightPaletteSelector x:Name="WeightedColorPalette"
19+
MinColorCount="1" />
20+
<helpers:BaseColorPaletteSelector x:Name="BasePalette"
21+
MinColorCount="1" />
22+
</helpers:ColorPaletteSampler>
1623
</Page.Resources>
1724

25+
<!--
26+
ConstrastHelper used to auto-adjust text Foreground against the dynamic background per WCAG.
27+
This is not a ContrastHelper sample, but is used here to ensure text is always readable.
28+
-->
1829
<Grid>
1930
<Grid.ColumnDefinitions>
2031
<ColumnDefinition Width="*" />
@@ -23,19 +34,17 @@
2334

2435
<StackPanel Padding="20"
2536
VerticalAlignment="Center">
26-
<Image x:Name="AccentedImage"
37+
<Image x:Name="SampledImage"
2738
HorizontalAlignment="Center"
2839
Source="/ColorAnalyzerExperiment.Samples/Assets/StockImages/Flowers.jpg"
2940
Stretch="Uniform">
3041
<interactivity:Interaction.Behaviors>
3142
<interactivity:EventTriggerBehavior EventName="ImageOpened">
32-
<interactivity:CallMethodAction MethodName="UpdateAccent"
33-
TargetObject="{x:Bind AccentAnalyzer}" />
43+
<interactivity:CallMethodAction MethodName="UpdatePalette"
44+
TargetObject="{x:Bind ColorPaletteSampler}" />
3445
</interactivity:EventTriggerBehavior>
3546
</interactivity:Interaction.Behaviors>
3647
</Image>
37-
<TextBlock HorizontalAlignment="Center"
38-
Text="{x:Bind AccentAnalyzer.Colorfulness, Mode=OneWay}" />
3948
</StackPanel>
4049

4150
<Grid Grid.Column="1"
@@ -60,9 +69,9 @@
6069
Margin="4"
6170
Padding="2">
6271
<Border.Background>
63-
<SolidColorBrush Color="{x:Bind AccentAnalyzer.DominantColor, Mode=OneWay}" />
72+
<SolidColorBrush Color="{x:Bind WeightedColorPalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}" />
6473
</Border.Background>
65-
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind AccentAnalyzer.DominantColor, Mode=OneWay}"
74+
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind WeightedColorPalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}"
6675
Text="Dominant" />
6776
</Border>
6877

@@ -72,14 +81,14 @@
7281
Margin="4"
7382
Padding="2">
7483
<Border.Background>
75-
<SolidColorBrush Color="{x:Bind AccentAnalyzer.BaseColor, Mode=OneWay}" />
84+
<SolidColorBrush Color="{x:Bind BasePalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}" />
7685
</Border.Background>
7786
<TextBlock Text="Base">
7887
<TextBlock.Foreground>
79-
<!-- ConstrastHelper used to auto-adjust text Foreground against the dynamic background per WCAG -->
88+
8089
<SolidColorBrush helpers:ContrastHelper.MinRatio="5"
81-
helpers:ContrastHelper.Opponent="{x:Bind AccentAnalyzer.BaseColor, Mode=OneWay}"
82-
Color="{x:Bind AccentAnalyzer.PrimaryAccentColor, Mode=OneWay}" />
90+
helpers:ContrastHelper.Opponent="{x:Bind BasePalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}"
91+
Color="{x:Bind AccentPalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}" />
8392
</TextBlock.Foreground>
8493
</TextBlock>
8594
</Border>
@@ -90,9 +99,9 @@
9099
Margin="4"
91100
Padding="2">
92101
<Border.Background>
93-
<SolidColorBrush Color="{x:Bind AccentAnalyzer.PrimaryAccentColor, Mode=OneWay}" />
102+
<SolidColorBrush Color="{x:Bind AccentPalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}" />
94103
</Border.Background>
95-
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind AccentAnalyzer.PrimaryAccentColor, Mode=OneWay}"
104+
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind AccentPalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}"
96105
Text="Primary" />
97106
</Border>
98107
<!-- Secondary -->
@@ -101,9 +110,9 @@
101110
Margin="4"
102111
Padding="2">
103112
<Border.Background>
104-
<SolidColorBrush Color="{x:Bind AccentAnalyzer.SecondaryAccentColor, Mode=OneWay}" />
113+
<SolidColorBrush Color="{x:Bind AccentPalette.SelectedColors[1], FallbackValue=Transparent, Mode=OneWay}" />
105114
</Border.Background>
106-
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind AccentAnalyzer.SecondaryAccentColor, Mode=OneWay}"
115+
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind AccentPalette.SelectedColors[1], FallbackValue=Transparent, Mode=OneWay}"
107116
Text="Secondary" />
108117
</Border>
109118
<!-- Tertiary -->
@@ -112,9 +121,9 @@
112121
Margin="4"
113122
Padding="2">
114123
<Border.Background>
115-
<SolidColorBrush Color="{x:Bind AccentAnalyzer.TertiaryAccentColor, Mode=OneWay}" />
124+
<SolidColorBrush Color="{x:Bind AccentPalette.SelectedColors[2], FallbackValue=Transparent, Mode=OneWay}" />
116125
</Border.Background>
117-
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind AccentAnalyzer.TertiaryAccentColor, Mode=OneWay}"
126+
<TextBlock helpers:ContrastHelper.Opponent="{x:Bind AccentPalette.SelectedColors[2], FallbackValue=Transparent, Mode=OneWay}"
118127
Text="Tertiary" />
119128
</Border>
120129

@@ -125,9 +134,9 @@
125134
<Rectangle.Fill>
126135
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
127136
<GradientStopCollection>
128-
<GradientStop Offset="0" Color="{x:Bind AccentAnalyzer.PrimaryAccentColor, Mode=OneWay}" />
129-
<GradientStop Offset="0.74" Color="{x:Bind AccentAnalyzer.SecondaryAccentColor, Mode=OneWay}" />
130-
<GradientStop Offset="1" Color="{x:Bind AccentAnalyzer.TertiaryAccentColor, Mode=OneWay}" />
137+
<GradientStop Offset="0" Color="{x:Bind AccentPalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}" />
138+
<GradientStop Offset="0.74" Color="{x:Bind AccentPalette.SelectedColors[1], FallbackValue=Transparent, Mode=OneWay}" />
139+
<GradientStop Offset="1" Color="{x:Bind AccentPalette.SelectedColors[2], FallbackValue=Transparent, Mode=OneWay}" />
131140
</GradientStopCollection>
132141
</LinearGradientBrush>
133142
</Rectangle.Fill>

components/ColorAnalyzer/samples/ImageOptionsPane.xaml.cs renamed to components/ColorAnalyzer/samples/ColorPaletteSampler/ImageOptionsPane.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ private void GridView_ItemClick(object sender, ItemClickEventArgs e)
3939

4040
private void SetImage(Uri uri)
4141
{
42-
_sample.AccentedImage.Source = new BitmapImage(uri);
42+
_sample.SampledImage.Source = new BitmapImage(uri);
4343
}
4444
}

components/ColorAnalyzer/src/AccentAnalyzer.Properties.cs

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)