Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ColorPicker #241

Merged
merged 32 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
215833c
Init
niels9001 Sep 20, 2023
be939c7
Use default GetTemplateChild
niels9001 Sep 20, 2023
9809275
Visual updates
niels9001 Sep 20, 2023
a4cd709
Adding ColorPicker and ColorPickerButton
niels9001 Sep 23, 2023
6006bf3
XAML styler
niels9001 Sep 23, 2023
7441c3c
Merge branch 'main' into niels9001/colorpicker
niels9001 Sep 23, 2023
f19604b
Adding icon
niels9001 Sep 23, 2023
72e6e9a
Adding missing brushes
niels9001 Sep 23, 2023
e3505f8
Setting default width + fixing background bug
niels9001 Sep 23, 2023
f630d8b
Merge branch 'main' into niels9001/colorpicker
niels9001 Oct 6, 2023
3c96fa9
Fix CI
niels9001 Oct 6, 2023
f239728
Merge branch 'main' into niels9001/colorpicker
niels9001 Nov 28, 2023
0687e66
Merge branch 'main' into niels9001/colorpicker
Arlodotexe Jan 9, 2024
f661b12
Merge branch 'main' into niels9001/colorpicker
michael-hawker Jan 10, 2024
fb9fb6b
Update components/ColorPicker/src/ColorPickerSlider.Properties.cs
niels9001 Jan 10, 2024
a9d5395
Fixed PackageId
Arlodotexe Jan 18, 2024
00f6e74
Add ToolkitSegmentedSourceProject
Arlodotexe Jan 18, 2024
b84dc58
Use absolute paths for ProjectReference
Arlodotexe Jan 18, 2024
e3dd4be
Merge branch 'main' into niels9001/colorpicker
Arlodotexe Jan 24, 2024
33ee0cc
Fixed ProjectReference prop names
Arlodotexe Jan 24, 2024
7d7263a
Merge branch 'main' into niels9001/colorpicker
Arlodotexe Jan 30, 2024
45e2443
Merge branch 'main' into niels9001/colorpicker
Arlodotexe Jan 31, 2024
4e2c007
UI improvements
niels9001 Feb 1, 2024
08b5e0a
XAML styler
niels9001 Feb 1, 2024
146b4d9
Merge branch 'main' into niels9001/colorpicker
niels9001 Feb 1, 2024
5a48acf
Merge branch 'main' into niels9001/colorpicker
niels9001 Feb 8, 2024
54d9881
Merge branch 'main' into niels9001/colorpicker
Arlodotexe Feb 28, 2024
9524352
Include MSBuild.Sdk.Extras/3.0.23 on UWP only
Arlodotexe Feb 28, 2024
7186176
Merge branch 'main' into niels9001/colorpicker
Arlodotexe Feb 29, 2024
77fd1df
Merge branch 'main' into niels9001/colorpicker
niels9001 Mar 4, 2024
416c813
Workaround for Segmented layout files being included in ColorPicker
Arlodotexe Mar 5, 2024
95204d6
Merge branch 'main' into niels9001/colorpicker
Arlodotexe Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/ColorPicker/OpenSolution.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF

powershell ..\..\tooling\ProjectHeads\GenerateSingleSampleHeads.ps1 -componentPath %CD% %*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions components/ColorPicker/samples/ColorPicker.Samples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.23">
<PropertyGroup>
<ToolkitComponentName>ColorPicker</ToolkitComponentName>
</PropertyGroup>

<ItemGroup>
<None Remove="Assets\ColorPicker.png" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\ColorPicker.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<!-- Sets this up as a toolkit component's sample project -->
<Import Project="$(ToolingDirectory)\ToolkitComponent.SampleProject.props" />
</Project>
22 changes: 22 additions & 0 deletions components/ColorPicker/samples/ColorPicker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: ColorPicker
author: michael-hawker
description: An extended color picker control that lets a user pick a color using a color spectrum, sliders, or text input.
keywords: ColorPicker, Control, Layout
dev_langs:
- csharp
category: Controls
subcategory: Input
discussion-id: 0
issue-id: 0
icon: Assets/ColorPicker.png
---

The [ColorPicker](/dotnet/api/microsoft.toolkit.uwp.ui.controls.colorpicker) control lets a user pick a color using a color spectrum, palette, sliders, or text input.

> [!Sample ColorPickerSample]

## ColorPickerButton
The `ColorPickerButton` variant represents a `DropDownButton` variant which provides a preview of the selected color and allows a user to expand the drop-down to select a new color.

> [!Sample ColorPickerButtonSample]
16 changes: 16 additions & 0 deletions components/ColorPicker/samples/ColorPickerButtonSample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- 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. -->
<Page x:Class="ColorPickerExperiment.Samples.ColorPickerButtonSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:ColorPickerExperiment.Samples"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid>
<controls:ColorPickerButton HorizontalAlignment="Center"
VerticalAlignment="Top"
SelectedColor="LightBlue" />
</Grid>
</Page>
16 changes: 16 additions & 0 deletions components/ColorPicker/samples/ColorPickerButtonSample.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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.

using ColorSpectrumShape = Microsoft.UI.Xaml.Controls.ColorSpectrumShape;

namespace ColorPickerExperiment.Samples;

[ToolkitSample(id: nameof(ColorPickerButtonSample), "ColorPickerButton", description: $"A sample for showing how to create and use a {nameof(CommunityToolkit.WinUI.Controls.ColorPickerButton)} control.")]
public sealed partial class ColorPickerButtonSample : Page
{
public ColorPickerButtonSample()
{
this.InitializeComponent();
}
}
24 changes: 24 additions & 0 deletions components/ColorPicker/samples/ColorPickerSample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- 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. -->
<Page x:Class="ColorPickerExperiment.Samples.ColorPickerSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:ColorPickerExperiment.Samples"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid>
<controls:ColorPicker HorizontalAlignment="Center"
VerticalAlignment="Top"
ColorSpectrumShape="{x:Bind local:ColorPickerSample.ConvertStringToColorSpectrumShape(SpectrumShape), Mode=OneWay}"
IsAlphaEnabled="{x:Bind AlphaEnabled, Mode=OneWay}"
IsAlphaSliderVisible="{x:Bind AlphaSlider, Mode=OneWay}"
IsColorChannelTextInputVisible="{x:Bind ColorChannel, Mode=OneWay}"
IsColorPaletteVisible="{x:Bind ColorPalette, Mode=OneWay}"
IsColorSliderVisible="{x:Bind ColorSlider, Mode=OneWay}"
IsColorSpectrumVisible="{x:Bind SpectrumVisible, Mode=OneWay}"
ShowAccentColors="{x:Bind AccentColors, Mode=OneWay}"
Color="LightBlue" />
</Grid>
</Page>
34 changes: 34 additions & 0 deletions components/ColorPicker/samples/ColorPickerSample.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.

using ColorSpectrumShape = Microsoft.UI.Xaml.Controls.ColorSpectrumShape;

namespace ColorPickerExperiment.Samples;

[ToolkitSampleBoolOption("AccentColors", true, Title = "ShowAccentColors")]
[ToolkitSampleBoolOption("AlphaEnabled", true, Title = "IsAlphaEnabled")]
[ToolkitSampleBoolOption("AlphaSlider", true, Title = "IsAlphaSliderVisible")]
[ToolkitSampleBoolOption("ColorSlider", true, Title = "IsColorSliderVisible")]
[ToolkitSampleBoolOption("ColorChannel", true, Title = "IsColorChannelTextInputVisible")]
[ToolkitSampleBoolOption("SpectrumVisible", true, Title = "IsColorSpectrumVisible")]
[ToolkitSampleBoolOption("ColorPalette", true, Title = "IsColorPaletteVisible")]

[ToolkitSampleMultiChoiceOption("SpectrumShape", "Box", "Ring", Title = "ColorSpectrumShape")]

[ToolkitSample(id: nameof(ColorPickerSample), "ColorPicker", description: $"A sample for showing how to create and use a {nameof(CommunityToolkit.WinUI.Controls.ColorPicker)} control.")]
public sealed partial class ColorPickerSample : Page
{
public ColorPickerSample()
{
this.InitializeComponent();
}

// TODO: See https://github.com/CommunityToolkit/Labs-Windows/issues/149
public static ColorSpectrumShape ConvertStringToColorSpectrumShape(string shape) => shape switch
{
"Ring" => ColorSpectrumShape.Ring,
"Box" => ColorSpectrumShape.Box,
_ => throw new System.NotImplementedException(),
};
}
31 changes: 31 additions & 0 deletions components/ColorPicker/samples/Dependencies.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
WinUI 2 under UWP uses TargetFramework uap10.0.*
WinUI 3 under WinAppSdk uses TargetFramework net6.0-windows10.*
However, under Uno-powered platforms, both WinUI 2 and 3 can share the same TargetFramework.

MSBuild doesn't play nicely with this out of the box, so we've made it easy for you.

For .NET Standard packages, you can use the Nuget Package Manager in Visual Studio.
For UWP / WinAppSDK / Uno packages, place the package references here.
-->
<Project>
<!-- WinUI 2 / UWP -->
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> -->
</ItemGroup>

<!-- WinUI 2 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
<!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> -->
</ItemGroup>

<!-- WinUI 3 / WinAppSdk -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
<!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> -->
</ItemGroup>

<!-- WinUI 3 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
<!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> -->
</ItemGroup>
</Project>
32 changes: 32 additions & 0 deletions components/ColorPicker/src/ColorChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.

namespace CommunityToolkit.WinUI.Controls;

/// <summary>
/// Defines a specific channel within a color representation.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public enum ColorChannel
{
/// <summary>
/// Represents the alpha channel.
/// </summary>
Alpha,

/// <summary>
/// Represents the first color channel which is Red when RGB or Hue when HSV.
/// </summary>
Channel1,

/// <summary>
/// Represents the second color channel which is Green when RGB or Saturation when HSV.
/// </summary>
Channel2,

/// <summary>
/// Represents the third color channel which is Blue when RGB or Value when HSV.
/// </summary>
Channel3
}
143 changes: 143 additions & 0 deletions components/ColorPicker/src/ColorPicker.Properties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// 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.

namespace CommunityToolkit.WinUI.Controls;

/// <summary>
/// Contains all properties for the <see cref="ColorPicker"/>.
/// </summary>
public partial class ColorPicker
{
/// <summary>
/// Identifies the <see cref="CustomPaletteColors"/> dependency property.
/// </summary>
public static readonly DependencyProperty CustomPaletteColorsProperty =
DependencyProperty.Register(
nameof(CustomPaletteColors),
typeof(ObservableCollection<Windows.UI.Color>),
typeof(ColorPicker),
new PropertyMetadata(
null,
(s, e) => (s as ColorPicker)?.OnDependencyPropertyChanged(s, e)));

/// <summary>
/// Gets the list of custom palette colors.
/// </summary>
public ObservableCollection<Windows.UI.Color> CustomPaletteColors
{
get => (ObservableCollection<Windows.UI.Color>)this.GetValue(CustomPaletteColorsProperty);
}

/// <summary>
/// Identifies the <see cref="CustomPaletteColumnCount"/> dependency property.
/// </summary>
public static readonly DependencyProperty CustomPaletteColumnCountProperty =
DependencyProperty.Register(
nameof(CustomPaletteColumnCount),
typeof(int),
typeof(ColorPicker),
new PropertyMetadata(
4,
(s, e) => (s as ColorPicker)?.OnDependencyPropertyChanged(s, e)));

/// <summary>
/// Gets or sets the number of colors in each row (section) of the custom color palette.
/// Within a standard palette, rows are shades and columns are unique colors.
/// </summary>
public int CustomPaletteColumnCount
{
get => (int)this.GetValue(CustomPaletteColumnCountProperty);
set
{
if (object.Equals(value, this.GetValue(CustomPaletteColumnCountProperty)) == false)
{
this.SetValue(CustomPaletteColumnCountProperty, value);
}
}
}

/// <summary>
/// Identifies the <see cref="CustomPalette"/> dependency property.
/// </summary>
public static readonly DependencyProperty CustomPaletteProperty =
DependencyProperty.Register(
nameof(CustomPalette),
typeof(IColorPalette),
typeof(ColorPicker),
new PropertyMetadata(
null,
(s, e) => (s as ColorPicker)?.OnDependencyPropertyChanged(s, e)));

/// <summary>
/// Gets or sets the custom color palette.
/// This will automatically set <see cref="CustomPaletteColors"/> and <see cref="CustomPaletteColumnCount"/>
/// overwriting any existing values.
/// </summary>
public IColorPalette CustomPalette
{
get => (IColorPalette)this.GetValue(CustomPaletteProperty);
set
{
if (object.Equals(value, this.GetValue(CustomPaletteProperty)) == false)
{
this.SetValue(CustomPaletteProperty, value);
}
}
}

/// <summary>
/// Identifies the <see cref="IsColorPaletteVisible"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsColorPaletteVisibleProperty =
DependencyProperty.Register(
nameof(IsColorPaletteVisible),
typeof(bool),
typeof(ColorPicker),
new PropertyMetadata(
true,
(s, e) => (s as ColorPicker)?.OnDependencyPropertyChanged(s, e)));

/// <summary>
/// Gets or sets a value indicating whether the color palette is visible.
/// </summary>
public bool IsColorPaletteVisible
{
get => (bool)this.GetValue(IsColorPaletteVisibleProperty);
set
{
if (object.Equals(value, this.GetValue(IsColorPaletteVisibleProperty)) == false)
{
this.SetValue(IsColorPaletteVisibleProperty, value);
}
}
}

/// <summary>
/// Identifies the <see cref="ShowAccentColors"/> dependency property.
/// </summary>
public static readonly DependencyProperty ShowAccentColorsProperty =
DependencyProperty.Register(
nameof(ShowAccentColors),
typeof(bool),
typeof(ColorPicker),
new PropertyMetadata(
true,
(s, e) => (s as ColorPicker)?.OnDependencyPropertyChanged(s, e)));

/// <summary>
/// Gets or sets a value indicating whether accent colors are shown along
/// with the preview color.
/// </summary>
public bool ShowAccentColors
{
get => (bool)this.GetValue(ShowAccentColorsProperty);
set
{
if (object.Equals(value, this.GetValue(ShowAccentColorsProperty)) == false)
{
this.SetValue(ShowAccentColorsProperty, value);
}
}
}
}
Loading
Loading