Skip to content

Commit

Permalink
Merge pull request #41 from DHancock/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DHancock authored Dec 1, 2023
2 parents f2a9b18 + c03dcea commit 33649e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<Setter Property="Padding" Value="6"/>
</Style>

<Style TargetType="w3c:SimpleColorPicker">
<Setter Property="ShouldConstrainToRootBounds" Value="false"/>
</Style>

<Style TargetType="TextBlock">
<Setter Property="Margin" Value="0,0,10,0"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
Expand All @@ -72,16 +68,19 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Button Grid.Column="4" HorizontalAlignment="Right" Content="Toggle Theme" Click="Button_Click"/>
<Button Grid.Column="5" HorizontalAlignment="Right" Content="Toggle Theme" Click="Button_Click"/>

<TextBlock Grid.Row="1" Text="Defaults:"/>
<w3c:SimpleColorPicker Grid.Row="1" Grid.Column="1" Color="{x:Bind BC, Mode=TwoWay}" ColorChanged="SimpleColorPicker_ColorChanged"/>

<TextBlock Grid.Row="2" Text="Mini palette:"/>
<w3c:SimpleColorPicker Grid.Row="2" Grid.Column="1" IsMiniPalette="True" Color="{x:Bind BC, Mode=TwoWay}"/>
<w3c:SimpleColorPicker x:Name="MiniPaletePicker" Grid.Row="2" Grid.Column="1" IsMiniPalette="True" Color="{x:Bind BC, Mode=TwoWay}" />
<TextBlock Text="Initial selection mode" Grid.Row="2" Grid.Column="2"/>
<ComboBox x:Name="InitialSelectionComboBox" Loaded="InitialSelectionComboBox_Loaded" SelectionChanged="InitialSelectionComboBox_SelectionChanged" Grid.Row="2" Grid.Column="3"/>

<TextBlock Grid.Row="3" Text="Vertical palette orientation:"/>
<w3c:SimpleColorPicker Grid.Row="3" Grid.Column="1" PaletteOrientation="Vertical" Color="{x:Bind BC, Mode=TwoWay}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Windows.Foundation.Collections;
using Windows.UI;


// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

Expand Down Expand Up @@ -141,5 +142,17 @@ private void SimpleColorPicker_FlyoutClosed(AssyntSoftware.WinUI3Controls.Simple
{
eventReceivedFeedback.Text = "event received: Closed";
}

private void InitialSelectionComboBox_Loaded(object sender, RoutedEventArgs e)
{
InitialSelectionComboBox.ItemsSource = Enum.GetNames<AssyntSoftware.WinUI3Controls.SimpleColorPicker.InitialSelection>();
InitialSelectionComboBox.SelectedItem = InitialSelectionComboBox.Items[0];
}

private void InitialSelectionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
String value = (String)InitialSelectionComboBox.SelectedItem;
MiniPaletePicker.InitialSelectionMode = Enum.Parse<AssyntSoftware.WinUI3Controls.SimpleColorPicker.InitialSelection>(value);
}
}
}
7 changes: 3 additions & 4 deletions WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,9 @@ private void AttemptSelectCurrentColor()
}
else
{
static double PerceivedColorDifference(Color a, Color b)
static double SimpleColorDifference(Color a, Color b)
{
static double GrayScale(Color c) => (c.R * 0.30) + (c.G * 0.59) + (c.B * 0.11);
return Math.Abs(GrayScale(a) - GrayScale(b));
return Math.Pow(a.R - b.R, 2) + Math.Pow(a.G - b.G, 2) + Math.Pow(a.B - b.B, 2);
}

double minDifference = double.MaxValue;
Expand All @@ -573,7 +572,7 @@ static double PerceivedColorDifference(Color a, Color b)
{
if (child is Border border)
{
double difference = PerceivedColorDifference(Color, ((SolidColorBrush)border.Background).Color);
double difference = SimpleColorDifference(Color, ((SolidColorBrush)border.Background).Color);

if (difference < 0.00001)
{
Expand Down

0 comments on commit 33649e0

Please sign in to comment.