-
Notifications
You must be signed in to change notification settings - Fork 79
GradientSlider component creation #769
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
Draft
Avid29
wants to merge
27
commits into
CommunityToolkit:main
Choose a base branch
from
Avid29:gradient_slider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e9927d5
Create GradientSlider component
Avid29 2c608e4
Cut template code to basics
Avid29 1028e20
Added thumb and background population
Avid29 a1f814f
Styled GradientSliderThumb and added dragging events
Avid29 b6cb853
Added comments to GradientSlider public members
Avid29 3fe66b5
GradientSlider thumb drag handling
Avid29 f3552f4
Refined event subscriptions
Avid29 219be4c
Added color selection flyout to GradientSliderThumb
Avid29 3f01d0a
Applied XAML styling
Avid29 9b7756a
Set explicitly MUXC ColorPicker
Avid29 22871b7
Fixed Rectangle namespace in WinUI2
Avid29 fb8175a
Changed GradientSliderThumb to use explicit MUXC for ColorChangedEven…
Avid29 3c8cfdc
Merge branch 'main' into gradient_slider
Avid29 ecc79f2
Update components/GradientSlider/src/GradientSlider.cs
Avid29 3a68bb0
Added placeholder thumb for add position indicator
Avid29 ca021d1
XAML Styles
Avid29 29246b4
Added disabled regions for the placeholder thumb
Avid29 a9ee9af
Add stop on pointer press
Avid29 bfd18cf
Thumb drag-on-creation for GradientSlider
Avid29 633a05f
XAML
Avid29 9e0f37c
Changed default value of GradientStops
Avid29 60108d4
Added property to enabled/disable adding gradient stops
Avid29 a1307b8
Added FlowDirection override on default GradientSliderStyle
Avid29 4d7e543
Do the thing (XAML Styles)
Avid29 aa83779
Fixed Colors namespace in WinUI2
Avid29 b40b727
Changed GradientSlider to track position as Point with Y axis
Avid29 11bec84
Added Keydown adjustments to GradientSlider
Avid29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
15 changes: 15 additions & 0 deletions
15
components/GradientSlider/samples/GradientSlider.Samples.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project> | ||
| <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))')" /> | ||
|
|
||
| <PropertyGroup> | ||
| <ToolkitComponentName>GradientSlider</ToolkitComponentName> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Sets this up as a toolkit component's sample project --> | ||
| <Import Project="$(ToolingDirectory)\ToolkitComponent.SampleProject.props" /> | ||
| <ItemGroup> | ||
| <Compile Update="GradientSliderSample.xaml.cs"> | ||
| <DependentUpon>GradientSliderSample.xaml</DependentUpon> | ||
| </Compile> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| title: GradientSlider | ||
| author: githubaccount | ||
| description: TODO: Your experiment's description here | ||
| keywords: GradientSlider, Control, Layout | ||
| dev_langs: | ||
| - csharp | ||
| category: Controls | ||
| subcategory: Layout | ||
| discussion-id: 0 | ||
| issue-id: 0 | ||
| icon: assets/icon.png | ||
| --- | ||
|
|
||
| <!-- To know about all the available Markdown syntax, Check out https://docs.microsoft.com/contribute/markdown-reference --> | ||
| <!-- Ensure you remove all comments before submission, to ensure that there are no formatting issues when displaying this page. --> | ||
| <!-- It is recommended to check how the Documentation will look in the sample app, before Merging a PR --> | ||
| <!-- **Note:** All links to other docs.microsoft.com pages should be relative without locale, i.e. for the one above would be /contribute/markdown-reference --> | ||
| <!-- Included images should be optimized for size and not include any Intellectual Property references. --> | ||
|
|
||
| <!-- Be sure to update the discussion/issue numbers above with your Labs discussion/issue id numbers in order for UI links to them from the sample app to work. --> | ||
|
|
||
| # GradientSlider | ||
|
|
||
| > [!SAMPLE GradientSliderSample] |
23 changes: 23 additions & 0 deletions
23
components/GradientSlider/samples/GradientSliderSample.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <!-- 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="GradientSliderExperiment.Samples.GradientSliderSample" | ||
| 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:GradientSliderExperiment.Samples" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <StackPanel Spacing="16"> | ||
| <controls:GradientSlider IsAddStopsEnabled="{x:Bind CanAddStops, Mode=OneWay}"> | ||
| <controls:GradientSlider.GradientStops> | ||
| <GradientStopCollection> | ||
| <GradientStop Offset="0" Color="#FF0000" /> | ||
| <GradientStop Offset="0.3" Color="#00FF00" /> | ||
| <GradientStop Offset="0.66" Color="#0000FF" /> | ||
| <GradientStop Offset="1" Color="#FF0000" /> | ||
| </GradientStopCollection> | ||
| </controls:GradientSlider.GradientStops> | ||
| </controls:GradientSlider> | ||
| </StackPanel> | ||
| </Page> | ||
21 changes: 21 additions & 0 deletions
21
components/GradientSlider/samples/GradientSliderSample.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // 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 CommunityToolkit.WinUI.Controls; | ||
|
|
||
| namespace GradientSliderExperiment.Samples; | ||
|
|
||
| /// <summary> | ||
| /// An example sample page of a custom control inheriting from Panel. | ||
| /// </summary> | ||
|
|
||
| [ToolkitSample(id: nameof(GradientSliderSample), "Custom control", description: $"A sample for showing how to create and use a {nameof(GradientSlider)} custom control.")] | ||
| [ToolkitSampleBoolOption("CanAddStops", true, Title = nameof(GradientSlider.IsAddStopsEnabled))] | ||
| public sealed partial class GradientSliderSample : Page | ||
| { | ||
| public GradientSliderSample() | ||
| { | ||
| this.InitializeComponent(); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
components/GradientSlider/src/CommunityToolkit.WinUI.Controls.GradientSlider.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||||||||||
| <Project> | ||||||||||||||||||
| <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))')" /> | ||||||||||||||||||
|
|
||||||||||||||||||
| <PropertyGroup> | ||||||||||||||||||
| <ToolkitComponentName>GradientSlider</ToolkitComponentName> | ||||||||||||||||||
| <Description>This package contains GradientSlider.</Description> | ||||||||||||||||||
|
|
||||||||||||||||||
| <!-- Rns suffix is required for namespaces shared across projects. See https://github.com/CommunityToolkit/Labs-Windows/issues/152 --> | ||||||||||||||||||
| <RootNamespace>CommunityToolkit.WinUI.Controls.GradientSliderRns</RootNamespace> | ||||||||||||||||||
| </PropertyGroup> | ||||||||||||||||||
|
|
||||||||||||||||||
| <!-- Sets this up as a toolkit component's source project --> | ||||||||||||||||||
| <Import Project="$(ToolingDirectory)\ToolkitComponent.SourceProject.props" /> | ||||||||||||||||||
| </Project> | ||||||||||||||||||
|
Comment on lines
+13
to
+14
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We need the |
||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // 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; | ||
|
|
||
| public partial class GradientSlider | ||
| { | ||
| /// <summary> | ||
| /// Event raised when a thumb starts being dragged. | ||
| /// </summary> | ||
| public event DragStartedEventHandler? ThumbDragStarted; | ||
|
|
||
| /// <summary> | ||
| /// Event raised when a thumb ends being dragged. | ||
| /// </summary> | ||
| public event DragCompletedEventHandler? ThumbDragCompleted; | ||
|
|
||
| /// <summary> | ||
| /// Event raised when the gradient's value changes. | ||
| /// </summary> | ||
| public event EventHandler? ValueChanged; | ||
|
|
||
| /// <summary> | ||
| /// Called before the <see cref="ThumbDragStarted"/> event occurs. | ||
| /// </summary> | ||
| /// <param name="e">Event data for the event.</param> | ||
| protected virtual void OnThumbDragStarted(DragStartedEventArgs e) | ||
| { | ||
| ThumbDragStarted?.Invoke(this, e); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Called before the <see cref="ThumbDragCompleted"/> event occurs. | ||
| /// </summary> | ||
| /// <param name="e">Event data for the event.</param> | ||
| protected virtual void OnThumbDragCompleted(DragCompletedEventArgs e) | ||
| { | ||
| ThumbDragCompleted?.Invoke(this, e); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Called before the <see cref="ValueChanged"/> event occurs. | ||
| /// </summary> | ||
| protected virtual void OnValueChanged() | ||
| { | ||
| ValueChanged?.Invoke(this, EventArgs.Empty); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the developer doesn't specify any stops at the start? Could be good to have another example where it's bound to a collection (to show binding) but that collection is also empty to start?