Skip to content

Commit

Permalink
Add DefaultOnColor and DefaultOffColor
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Sep 11, 2024
1 parent c87cfa7 commit c99f802
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- Include PDB in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<AvaloniaVersion>11.0.10</AvaloniaVersion>
<AvaloniaVersion>11.1.3</AvaloniaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
Expand Down
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageDownload Include="nbgv" Version="[3.6.133]" />
<PackageDownload Include="nbgv" Version="[3.6.143]" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/CP.XamlLEDControl.WPF.TestApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
x:Class="CP.XamlLEDControl.WPF.TestApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rxNav="https://github.com/ChrisPulman/CrissCross.ui"
xmlns:rxNav="https://github.com/reactivemarbles/CrissCross.ui"
StartupUri="MainWindow.xaml">

<Application.Resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CrissCross.WPF.UI" Version="1.0.25" />
<PackageReference Include="CrissCross.WPF.UI" Version="2.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/CP.XamlLEDControl.WPF.TestApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CP.XamlLEDControl.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="https://github.com/ChrisPulman/CrissCross.ui"
xmlns:ui="https://github.com/reactivemarbles/CrissCross.ui"
x:Name="mainWindow"
Title="MainWindow"
Width="800"
Expand Down
1 change: 1 addition & 0 deletions src/CP.XamlLEDControl.WPF.TestApp/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
x:Name="led1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
DefaultOnColor="GreenYellow"
FontSize="22"
LEDSize="50"
LedOrientation="Vertical"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>WinExe</OutputType>
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
One for Windows with net7.0-windows TFM, one for MacOS with net7.0-macos and one with net7.0 TFM for Linux.-->
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down
1 change: 1 addition & 0 deletions src/XamlLEDControl.Avalonia.TestApp/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
x:Name="led1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
DefaultOnColor="Blue"
ActiveLed="1"
FontSize="22"
LEDSize="50"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
Expand Down
60 changes: 60 additions & 0 deletions src/XamlLEDControl.Avalonia/XamlLED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ public class XamlLED : ContentControl
defaultValue: new List<Color>([Colors.Red]),
defaultBindingMode: BindingMode.TwoWay);

/// <summary>
/// The default on color property.
/// </summary>
public static readonly StyledProperty<Color> DefaultOnColorProperty =
AvaloniaProperty.Register<XamlLED, Color>(
nameof(DefaultOnColor),
defaultValue: Colors.Green,
defaultBindingMode: BindingMode.TwoWay);

/// <summary>
/// The default off color property.
/// </summary>
public static readonly StyledProperty<Color> DefaultOffColorProperty =
AvaloniaProperty.Register<XamlLED, Color>(
nameof(DefaultOffColor),
defaultValue: Colors.Red,
defaultBindingMode: BindingMode.TwoWay);

/// <summary>
/// The off opacity property.
/// </summary>
Expand Down Expand Up @@ -112,7 +130,9 @@ static XamlLED()
TextProperty.Changed.Subscribe(OnTextChanged);
IsTrueProperty.Changed.Subscribe(OnIsTrueChanged);
LedOnColorsProperty.Changed.Subscribe(OnLedOnColorsChanged);
DefaultOnColorProperty.Changed.Subscribe(OnDefaultLedOnColorChanged);
LedOffColorsProperty.Changed.Subscribe(OnLedOffColorsChanged);
DefaultOffColorProperty.Changed.Subscribe(OnDefaultLedOffColorChanged);
ActiveLedProperty.Changed.Subscribe(OnActiveLedChanged);
TextPositionProperty.Changed.Subscribe(OnTextPositionChanged);
}
Expand Down Expand Up @@ -163,6 +183,28 @@ public List<Color> LedOnColors
set => SetValue(LedOnColorsProperty, value);
}

/// <summary>
/// Gets or sets colors of the leds in on mode. Amount of colors equal the amount of leds displayed.
/// </summary>
[Description("Gets or sets colors of the led in On mode.")]
[Category("Layout")]
public Color DefaultOnColor
{
get => GetValue(DefaultOnColorProperty);
set => SetValue(DefaultOnColorProperty, value);
}

/// <summary>
/// Gets or sets colors of the leds in off mode. Amount of colors equal the amount of leds displayed.
/// </summary>
[Description("Gets or sets colors of the led in On mode.")]
[Category("Layout")]
public Color DefaultOffColor
{
get => GetValue(DefaultOffColorProperty);
set => SetValue(DefaultOffColorProperty, value);
}

/// <summary>
/// Gets or sets the leds off.
/// </summary>
Expand Down Expand Up @@ -400,6 +442,24 @@ private static void OnLedOffColorsChanged(AvaloniaPropertyChangedEventArgs<List<
}
}

private static void OnDefaultLedOnColorChanged(AvaloniaPropertyChangedEventArgs<Color> args)
{
if (args.Sender is XamlLED led)
{
led.LedOnColors = [args.NewValue.Value];
led.LoadLeds(led, null!);
}
}

private static void OnDefaultLedOffColorChanged(AvaloniaPropertyChangedEventArgs<Color> args)
{
if (args.Sender is XamlLED led)
{
led.LedOffColors = [args.NewValue.Value];
led.LoadLeds(led, null!);
}
}

private static void OnActiveLedChanged(AvaloniaPropertyChangedEventArgs<int> args)
{
if (args.Sender is XamlLED led)
Expand Down
2 changes: 1 addition & 1 deletion src/XamlLEDControl.Avalonia/XamlLEDControl.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
Expand Down
90 changes: 84 additions & 6 deletions src/XamlLEDControl.WPF/XamlLED.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@ public class XamlLED : ContentControl
typeof(XamlLED),
new PropertyMetadata(40d, LedSizeChange));

/// <summary>
/// The default on color property.
/// </summary>
public static readonly DependencyProperty DefaultOnColorProperty =
DependencyProperty.Register(
nameof(DefaultOnColor),
typeof(Color),
typeof(XamlLED),
new FrameworkPropertyMetadata
{
DefaultValue = Colors.Green,
PropertyChangedCallback = LedOnColorsChanged,
});

/// <summary>
/// The default off color property.
/// </summary>
public static readonly DependencyProperty DefaultOffColorProperty =
DependencyProperty.Register(
nameof(DefaultOffColor),
typeof(Color),
typeof(XamlLED),
new FrameworkPropertyMetadata
{
DefaultValue = Colors.Red,
PropertyChangedCallback = LedOffColorsChanged,
});

private readonly List<Ellipse> _leds = [];
private readonly TextBlock _LedText = new();
private readonly StackPanel _ledStackPanel = new();
Expand Down Expand Up @@ -212,6 +240,22 @@ public List<Color> LedOnColors
set => SetValue(LedOnColorsProperty, value);
}

/// <summary>
/// Gets or sets the default color of the on.
/// </summary>
/// <value>
/// The default color of the on.
/// </value>
public Color DefaultOnColor
{
get => (Color)GetValue(DefaultOnColorProperty);
set
{
SetValue(DefaultOnColorProperty, value);
LedOnColors = new List<Color>([value]);
}
}

/// <summary>
/// Gets or sets the leds off.
/// </summary>
Expand All @@ -226,6 +270,22 @@ public List<Color> LedOffColors
set => SetValue(LedOffColorsProperty, value);
}

/// <summary>
/// Gets or sets the default color of the off.
/// </summary>
/// <value>
/// The default color of the off.
/// </value>
public Color DefaultOffColor
{
get => (Color)GetValue(DefaultOffColorProperty);
set
{
SetValue(DefaultOffColorProperty, value);
LedOffColors = new List<Color>([value]);
}
}

/// <summary>
/// Gets or sets the size of the led.
/// </summary>
Expand Down Expand Up @@ -378,19 +438,37 @@ private static void IsTruePropertyChanged(DependencyObject d, DependencyProperty

private static void LedOnColorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is XamlLED led && e.NewValue is List<Color> colors)
if (d is XamlLED led)
{
led.LedOnColors = colors;
led.LoadLeds(d, null!);
if (e.NewValue is List<Color> colors)
{
led.LedOnColors = colors;
led.LoadLeds(d, null!);
}

if (e.NewValue is Color color)
{
led.LedOnColors = [color];
led.LoadLeds(d, null!);
}
}
}

private static void LedOffColorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is XamlLED led && e.NewValue is List<Color> colors)
if (d is XamlLED led)
{
led.LedOffColors = colors;
led.LoadLeds(d, null!);
if (e.NewValue is List<Color> colors)
{
led.LedOffColors = colors;
led.LoadLeds(d, null!);
}

if (e.NewValue is Color color)
{
led.LedOffColors = [color];
led.LoadLeds(d, null!);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/XamlLEDControl.WPF/XamlLEDControl.WPF.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;net6.0-windows;net7.0-windows;net8.0-windows</TargetFrameworks>
<TargetFrameworks>net462;net6.0-windows;net8.0-windows</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.1.1",
"version": "1.2.0",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down

0 comments on commit c99f802

Please sign in to comment.