Skip to content

Commit

Permalink
Added the possibility to only show the best scores (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Feb 24, 2024
1 parent 214b55c commit ecb12da
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 7 deletions.
44 changes: 43 additions & 1 deletion ColorPicker/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,49 @@
</Setter.Value>
</Setter>
</Style>

<Style x:Key="DefaultToggleButton" TargetType="{x:Type RadioButton}">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Border
x:Name="border"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="5"
SnapsToDevicePixels="true">
<ContentPresenter
x:Name="contentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="{DynamicResource LightAccentColor}" />
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource LightAccentColor}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="{DynamicResource LightAccentColor}" />
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource LightAccentColor}" />
</Trigger>
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="border" Property="Background" Value="{DynamicResource LightAccentColor}" />
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource LightAccentColor}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="border" Property="Background" Value="Transparent" />
<Setter TargetName="border" Property="BorderBrush" Value="Transparent" />
<Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="{DynamicResource Gray}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Background" Value="Transparent" />
Expand Down
15 changes: 14 additions & 1 deletion ColorPicker/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ public static (string, int) GetContrast(int[] rgb1, int[] rgb2)
return (result.ToString(), gridRow);
}

public static double GetContrastDouble(int[] rgb1, int[] rgb2)
{
var lum1 = GetLuminance(rgb1[0], rgb1[1], rgb1[2]);
var lum2 = GetLuminance(rgb2[0], rgb2[1], rgb2[2]);

var brightest = Math.Max(lum1, lum2);
var darkest = Math.Min(lum1, lum2);

var result = Math.Round((brightest + 0.05) / (darkest + 0.05), 4);

return result;
}

public static RGB[] GetShades(HSL hsl)
{
RGB[] colorPalette = new RGB[10];
Expand Down Expand Up @@ -293,7 +306,7 @@ public static void ChangeTheme(bool reload = false)
HarmoniesPage.CheckButton(HarmoniesPage.SelectedColorBtn);
PalettePage.CheckButton(PalettePage.SelectedColorBtn);
ContrastPage.CheckButton(ContrastPage.RgbBtn);
ContrastPage.InitGrid();
ContrastPage.InitGrid(ContrastPage.contrastLimit);
RefreshButton();
}

Expand Down
41 changes: 40 additions & 1 deletion ColorPicker/Pages/ContrastPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
Expand Down Expand Up @@ -392,7 +393,45 @@
</Button>
</Grid>
</Border>
<Grid x:Name="ContrastGrid" Grid.Row="2">
<StackPanel
Grid.Row="2"
Margin="10 0 0 0"
Orientation="Horizontal">
<RadioButton
x:Name="ScoreAllToggle"
Margin="0 0 2 0"
Padding="3"
Background="Transparent"
Checked="ScoreAllToggle_Checked"
Content="{x:Static lang:Resources.ScoreAll}"
FontWeight="Bold"
Foreground="{DynamicResource AccentColor}"
GroupName="ScoreToggles"
Style="{DynamicResource DefaultToggleButton}" />
<RadioButton
x:Name="ScoreAAToggle"
Margin="2 0"
Padding="3"
Background="Transparent"
Checked="ScoreAAToggle_Checked"
Content="{x:Static lang:Resources.ScoreAA}"
FontWeight="Bold"
Foreground="{DynamicResource AccentColor}"
GroupName="ScoreToggles"
Style="{DynamicResource DefaultToggleButton}" />
<RadioButton
x:Name="ScoreAAAToggle"
Margin="2 0"
Padding="3"
Background="Transparent"
Checked="ScoreAAAToggle_Checked"
Content="{x:Static lang:Resources.ScoreAAA}"
FontWeight="Bold"
Foreground="{DynamicResource AccentColor}"
GroupName="ScoreToggles"
Style="{DynamicResource DefaultToggleButton}" />
</StackPanel>
<Grid x:Name="ContrastGrid" Grid.Row="3">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
Expand Down
26 changes: 22 additions & 4 deletions ColorPicker/Pages/ContrastPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ private void LoadInputUI()
Txt5.Text = ColorInfo.DEC.Value.ToString();
}
}

internal double contrastLimit = 0;
private void Txt1_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
InitGrid();
InitGrid(contrastLimit);
}
catch { }
}
Expand Down Expand Up @@ -351,7 +351,7 @@ private void BookmarkBtn_Click(object sender, RoutedEventArgs e)
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;
}

internal void InitGrid()
internal void InitGrid(double limit)
{
ColorInfo = new ColorInfo(ConvertToRgb());
var color = Color.FromRgb(ColorInfo.RGB.R, ColorInfo.RGB.G, ColorInfo.RGB.B);
Expand Down Expand Up @@ -406,7 +406,7 @@ internal void InitGrid()
{
for (int j = 0; j < colors.Count; j++)
{
var colorItem = new ColorGridItem(colors[i], colors[j]);
var colorItem = new ColorGridItem(colors[i], colors[j], limit);
Grid.SetRow(colorItem, 10 - i + 1);
Grid.SetColumn(colorItem, 10 - j + 1);
ContrastGrid.Children.Add(colorItem);
Expand All @@ -424,4 +424,22 @@ internal void InitGrid()
BookmarkToolTip.Content = Properties.Resources.RemoveBookmark;

}

private void ScoreAllToggle_Checked(object sender, RoutedEventArgs e)
{
contrastLimit = 0;
InitGrid(contrastLimit);
}

private void ScoreAAToggle_Checked(object sender, RoutedEventArgs e)
{
contrastLimit = 4.5;
InitGrid(contrastLimit);
}

private void ScoreAAAToggle_Checked(object sender, RoutedEventArgs e)
{
contrastLimit = 7;
InitGrid(contrastLimit);
}
}

0 comments on commit ecb12da

Please sign in to comment.