Skip to content

Commit

Permalink
(chocolateyGH-685) Add additional Chocolatey colors and brushes
Browse files Browse the repository at this point in the history
Also introduce resource keys for chocolatey colors and brushes.
  • Loading branch information
punker76 committed Mar 2, 2021
1 parent c786091 commit de2b3a5
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
<Compile Include="Providers\IPlatformProvider.cs" />
<Compile Include="Providers\PlatformProvider\Windows7PlatformProvider.cs" />
<Compile Include="Theming\BundledTheme.cs" />
<Compile Include="Theming\ChocolateyBrushes.cs" />
<Compile Include="Theming\ChocolateyColors.cs" />
<Compile Include="Theming\ThemeAssist.cs" />
<Compile Include="SerilogLogger.cs" />
<Compile Include="Services\ChocolateyService.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
xmlns:properties="clr-namespace:ChocolateyGui.Common.Properties;assembly=ChocolateyGui.Common"
xmlns:controls="clr-namespace:ChocolateyGui.Common.Windows.Controls"
xmlns:dialogs="clr-namespace:ChocolateyGui.Common.Windows.Controls.Dialogs"
xmlns:theming="clr-namespace:ChocolateyGui.Common.Windows.Theming"
mc:Ignorable="d"
x:Class="ChocolateyGui.Common.Windows.Controls.Dialogs.ChocolateyDialog"
x:Name="PART_Dialog"
Background="{DynamicResource BackgroundColorBrush}" d:DesignWidth="1300">
Background="{DynamicResource {x:Static theming:ChocolateyBrushes.BackgroundKey}}" d:DesignWidth="1300">
<MahDialogs:CustomDialog.Content>
<Grid>
<Grid.RowDefinitions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf">
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
xmlns:theming="clr-namespace:ChocolateyGui.Common.Windows.Theming">

<!-- Document styles -->
<Style TargetType="{x:Type FlowDocument}"
Expand All @@ -10,7 +11,7 @@
<Setter Property="FontFamily" Value="{DynamicResource MahApps.Fonts.Family.Control}" />
<Setter Property="FontSize" Value="{DynamicResource MahApps.Font.Size.Default}" />
<Setter Property="PagePadding" Value="4" />
<Setter Property="Foreground" Value="{DynamicResource BodyColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.BodyKey}}" />
</Style>
<Style TargetType="{x:Type List}">
<Setter Property="Margin" Value="0 14" />
Expand All @@ -20,7 +21,7 @@
x:Key="{x:Static markdig:Styles.ParagraphStyleKey}">
<Setter Property="FontFamily" Value="{DynamicResource MahApps.Fonts.Family.Control}" />
<Setter Property="FontSize" Value="{DynamicResource MahApps.Font.Size.Default}" />
<Setter Property="Foreground" Value="{DynamicResource BodyColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.BodyKey}}" />
</Style>
<Style TargetType="{x:Type Paragraph}"
x:Key="{x:Static markdig:Styles.CodeBlockStyleKey}"
Expand Down Expand Up @@ -171,7 +172,7 @@
<Setter Property="mah:HeaderedControlHelper.HeaderForeground" Value="{DynamicResource MahApps.Brushes.Gray1}" />
<Setter Property="FontFamily" Value="{DynamicResource MahApps.Fonts.Family.Control}" />
<Setter Property="FontSize" Value="{DynamicResource MahApps.Font.Size.Default}" />
<Setter Property="Foreground" Value="{DynamicResource BodyColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.BodyKey}}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="Padding" Value="2 4" />
<Setter Property="Margin" Value="0 0 0 8" />
Expand Down
15 changes: 9 additions & 6 deletions Source/ChocolateyGui.Common.Windows/Resources/Controls.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:commands="clr-namespace:ChocolateyGui.Common.Windows.Commands"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:theming="clr-namespace:ChocolateyGui.Common.Windows.Theming"
mc:Ignorable="d">

<ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -308,11 +309,13 @@
</Style>

<Style x:Key="TileOutOfDateOverlayStyle" TargetType="{x:Type ContentControl}" BasedOn="{StaticResource TileOverlayStyle}">
<Setter Property="Background" Value="#A90000" />
<Setter Property="Background" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.OutOfDateKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.OutOfDateForegroundKey}}" />
</Style>

<Style x:Key="TileIsInstalledOverlayStyle" TargetType="{x:Type ContentControl}" BasedOn="{StaticResource TileOverlayStyle}">
<Setter Property="Background" Value="#007F00" />
<Setter Property="Background" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.IsInstalledKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.IsInstalledForegroundKey}}" />
</Style>

<Style x:Key="TileTitleTextStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
Expand Down Expand Up @@ -440,27 +443,27 @@
</Style>

<Style x:Key="PackageResourceValue" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{DynamicResource BodyColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.BodyKey}}" />
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Padding" Value="5" />
<Setter Property="Margin" Value="0 0 0 5" />
</Style>

<Style x:Key="TitleTextStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{DynamicResource BodyColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.BodyKey}}" />
<Setter Property="FontSize" Value="48" />
<Setter Property="Margin" Value="3,0,0,5" />
</Style>

<Style x:Key="SubtitleTextStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{DynamicResource BodyColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.BodyKey}}" />
<Setter Property="FontSize" Value="22" />
<Setter Property="Margin" Value="3,0,0,10" />
</Style>

<Style x:Key="SubtitleRunTextStyle" TargetType="{x:Type Run}">
<Setter Property="Foreground" Value="{DynamicResource BodyColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static theming:ChocolateyBrushes.BodyKey}}" />
<Setter Property="FontSize" Value="22" />
</Style>

Expand Down
29 changes: 25 additions & 4 deletions Source/ChocolateyGui.Common.Windows/Theming/BundledTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,33 @@ private static Theme GenerateTheme(string scheme, bool isDark)
isHighContrast: false);

var backgroundColor = isDark ? ThemeAssist.ColorFromString("#333333") : ThemeAssist.ColorFromString("#F0EEE0");
theme.Resources["BackgroundColor"] = backgroundColor;
theme.Resources["BackgroundColorBrush"] = backgroundColor.ToBrush();
theme.Resources[ChocolateyColors.BackgroundKey] = backgroundColor;
theme.Resources[ChocolateyBrushes.BackgroundKey] = backgroundColor.ToBrush();

var bodyColor = isDark ? ThemeAssist.ColorFromString("#F0EEE0") : ThemeAssist.ColorFromString("#333333");
theme.Resources["BodyColor"] = bodyColor;
theme.Resources["BodyColorBrush"] = bodyColor.ToBrush();
theme.Resources[ChocolateyColors.BodyKey] = bodyColor;
theme.Resources[ChocolateyBrushes.BodyKey] = bodyColor.ToBrush();

var outOfDateColor = ThemeAssist.ColorFromString("#b71c1c");
theme.Resources[ChocolateyColors.OutOfDateKey] = outOfDateColor;
theme.Resources[ChocolateyBrushes.OutOfDateKey] = outOfDateColor.ToBrush();

theme.Resources[ChocolateyColors.OutOfDateForegroundKey] = Colors.White;
theme.Resources[ChocolateyBrushes.OutOfDateForegroundKey] = Colors.White.ToBrush();

var isInstalledColor = ThemeAssist.ColorFromString("#1b5e20");
theme.Resources[ChocolateyColors.IsInstalledKey] = isInstalledColor;
theme.Resources[ChocolateyBrushes.IsInstalledKey] = isInstalledColor.ToBrush();

theme.Resources[ChocolateyColors.IsInstalledForegroundKey] = Colors.White;
theme.Resources[ChocolateyBrushes.IsInstalledForegroundKey] = Colors.White.ToBrush();

var preReleaseColor = ThemeAssist.ColorFromString("#ff8f00");
theme.Resources[ChocolateyColors.PreReleaseKey] = preReleaseColor;
theme.Resources[ChocolateyBrushes.PreReleaseKey] = preReleaseColor.ToBrush();

theme.Resources[ChocolateyColors.PreReleaseForegroundKey] = Colors.Black;
theme.Resources[ChocolateyBrushes.PreReleaseForegroundKey] = Colors.Black.ToBrush();

return theme;
}
Expand Down
54 changes: 54 additions & 0 deletions Source/ChocolateyGui.Common.Windows/Theming/ChocolateyBrushes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ChocolateyBrushes.cs" company="Chocolatey">
// Copyright 2017 - Present Chocolatey Software, LLC
// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Windows;

namespace ChocolateyGui.Common.Windows.Theming
{
public static class ChocolateyBrushes
{
/// <summary>
/// Gets the resource key for the background brush.
/// </summary>
public static ComponentResourceKey BackgroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.Background");

/// <summary>
/// Gets the resource key for the body brush.
/// </summary>
public static ComponentResourceKey BodyKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.Body");

/// <summary>
/// Gets the resource key for the out of date brush.
/// </summary>
public static ComponentResourceKey OutOfDateKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.OutOfDate");

/// <summary>
/// Gets the resource key for the out of date foreground brush.
/// </summary>
public static ComponentResourceKey OutOfDateForegroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.OutOfDate.Foreground");

/// <summary>
/// Gets the resource key for the installed brush.
/// </summary>
public static ComponentResourceKey IsInstalledKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.IsInstalled");

/// <summary>
/// Gets the resource key for the installed foreground brush.
/// </summary>
public static ComponentResourceKey IsInstalledForegroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.IsInstalled.Foreground");

/// <summary>
/// Gets the resource key for the pre-release brush.
/// </summary>
public static ComponentResourceKey PreReleaseKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.PreRelease");

/// <summary>
/// Gets the resource key for the pre-release foreground brush.
/// </summary>
public static ComponentResourceKey PreReleaseForegroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Brushes.PreRelease.Foreground");
}
}
54 changes: 54 additions & 0 deletions Source/ChocolateyGui.Common.Windows/Theming/ChocolateyColors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ChocolateyColors.cs" company="Chocolatey">
// Copyright 2017 - Present Chocolatey Software, LLC
// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Windows;

namespace ChocolateyGui.Common.Windows.Theming
{
public static class ChocolateyColors
{
/// <summary>
/// Gets the resource key for the background color.
/// </summary>
public static ComponentResourceKey BackgroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Colors.Background");

/// <summary>
/// Gets the resource key for the body color.
/// </summary>
public static ComponentResourceKey BodyKey { get; } = new ComponentResourceKey(typeof(ChocolateyBrushes), "Chocolatey.Colors.Body");

/// <summary>
/// Gets the resource key for the out of date color.
/// </summary>
public static ComponentResourceKey OutOfDateKey { get; } = new ComponentResourceKey(typeof(ChocolateyColors), "Chocolatey.Colors.OutOfDate");

/// <summary>
/// Gets the resource key for the out of date foreground color.
/// </summary>
public static ComponentResourceKey OutOfDateForegroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyColors), "Chocolatey.Colors.OutOfDate.Foreground");

/// <summary>
/// Gets the resource key for the installed color.
/// </summary>
public static ComponentResourceKey IsInstalledKey { get; } = new ComponentResourceKey(typeof(ChocolateyColors), "Chocolatey.Colors.IsInstalled");

/// <summary>
/// Gets the resource key for the installed foreground color.
/// </summary>
public static ComponentResourceKey IsInstalledForegroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyColors), "Chocolatey.Colors.IsInstalled.Foreground");

/// <summary>
/// Gets the resource key for the pre-release color.
/// </summary>
public static ComponentResourceKey PreReleaseKey { get; } = new ComponentResourceKey(typeof(ChocolateyColors), "Chocolatey.Colors.PreRelease");

/// <summary>
/// Gets the resource key for the pre-release foreground color.
/// </summary>
public static ComponentResourceKey PreReleaseForegroundKey { get; } = new ComponentResourceKey(typeof(ChocolateyColors), "Chocolatey.Colors.PreRelease.Foreground");
}
}
3 changes: 2 additions & 1 deletion Source/ChocolateyGui.Common.Windows/Views/AboutView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
xmlns:properties="clr-namespace:ChocolateyGui.Common.Properties;assembly=ChocolateyGui.Common"
xmlns:viewModels="clr-namespace:ChocolateyGui.Common.Windows.ViewModels;assembly=ChocolateyGui.Common.Windows"
xmlns:controls="clr-namespace:ChocolateyGui.Common.Windows.Controls"
xmlns:theming="clr-namespace:ChocolateyGui.Common.Windows.Theming"
mc:Ignorable="d"
Background="{DynamicResource BackgroundColorBrush}"
Background="{DynamicResource {x:Static theming:ChocolateyBrushes.BackgroundKey}}"
d:DataContext="{d:DesignInstance Type=viewModels:AboutViewModel, IsDesignTimeCreatable=False}"
d:DesignHeight="786" d:DesignWidth="1366">

Expand Down
Loading

0 comments on commit de2b3a5

Please sign in to comment.