Skip to content

Commit

Permalink
Merge branch 'main' into niels9001/segmented-sample
Browse files Browse the repository at this point in the history
  • Loading branch information
niels9001 committed Jan 31, 2024
2 parents 463c68a + ea17664 commit 30114dd
Show file tree
Hide file tree
Showing 47 changed files with 316 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"uno.check": {
"version": "1.14.1",
"version": "1.18.1",
"commands": [
"uno-check"
]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
- name: Restore dotnet tools
run: dotnet tool restore

# Pinning Manifest for 1.13 version of Uno.Check at the moment to unblock build, see https://github.com/CommunityToolkit/Windows/pull/201
# Pinning Manifest for 1.18 version of Uno.Check at the moment to unblock build, see https://github.com/CommunityToolkit/Windows/pull/320
- name: Run Uno Check to Install Dependencies
run: >
dotnet tool run uno-check
Expand All @@ -119,7 +119,7 @@ jobs:
--skip androidemulator
--skip vswinworkloads
--verbose
--manifest https://raw.githubusercontent.com/unoplatform/uno.check/c3b289d7bb16a2a2df7f7f7f848d76fe1e74036d/manifests/uno.ui.manifest.json
--manifest https://raw.githubusercontent.com/unoplatform/uno.check/1660eba219684491362704c75153b40ce6ef7a35/manifests/uno.ui.manifest.json
- name: Add msbuild to PATH
uses: microsoft/[email protected]
Expand Down
13 changes: 7 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Project>
<PropertyGroup>
<MajorVersion>8</MajorVersion>
<MinorVersion>0</MinorVersion>
<MinorVersion>1</MinorVersion>

<PackageIdPrefix>CommunityToolkit</PackageIdPrefix>
<RepositoryDirectory>$([MSBuild]::EnsureTrailingSlash('$(MSBuildThisFileDirectory)'))</RepositoryDirectory>
<ToolingDirectory>$(RepositoryDirectory)tooling</ToolingDirectory>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<ToolkitConvertersSourceProject>$(RepositoryDirectory)components\Converters\src\CommunityToolkit.WinUI.Converters.csproj</ToolkitConvertersSourceProject>
<ToolkitExtensionSourceProject>$(RepositoryDirectory)components\Extensions\src\CommunityToolkit.WinUI.Extensions.csproj</ToolkitExtensionSourceProject>
<ToolkitExtensionsSourceProject>$(RepositoryDirectory)components\Extensions\src\CommunityToolkit.WinUI.Extensions.csproj</ToolkitExtensionsSourceProject>
<ToolkitTriggersSourceProject>$(RepositoryDirectory)components\Triggers\src\CommunityToolkit.WinUI.Triggers.csproj</ToolkitTriggersSourceProject>
<ToolkitSettingsControlsSourceProject>$(RepositoryDirectory)components\SettingsControls\src\CommunityToolkit.WinUI.Controls.SettingsControls.csproj</ToolkitSettingsControlsSourceProject>

<!-- TODO: See https://github.com/CommunityToolkit/Windows/issues/117 these should be removed unless needed by sample app or tests -->
<ToolkitHelperSourceProject>$(RepositoryDirectory)components\Helpers\src\CommunityToolkit.WinUI.Helpers.csproj</ToolkitHelperSourceProject>
<ToolkitBehaviorSourceProject>$(RepositoryDirectory)components\Behaviors\src\CommunityToolkit.WinUI.Behaviors.csproj</ToolkitBehaviorSourceProject>
<ToolkitAnimationSourceProject>$(RepositoryDirectory)components\Animations\src\CommunityToolkit.WinUI.Animations.csproj</ToolkitAnimationSourceProject>
<ToolkitPrimitiveSourceProject>$(RepositoryDirectory)components\Primitives\src\CommunityToolkit.WinUI.Controls.Primitives.csproj</ToolkitPrimitiveSourceProject>
<ToolkitHelpersSourceProject>$(RepositoryDirectory)components\Helpers\src\CommunityToolkit.WinUI.Helpers.csproj</ToolkitHelpersSourceProject>
<ToolkitBehaviorsSourceProject>$(RepositoryDirectory)components\Behaviors\src\CommunityToolkit.WinUI.Behaviors.csproj</ToolkitBehaviorsSourceProject>
<ToolkitAnimationsSourceProject>$(RepositoryDirectory)components\Animations\src\CommunityToolkit.WinUI.Animations.csproj</ToolkitAnimationsSourceProject>
<ToolkitPrimitivesSourceProject>$(RepositoryDirectory)components\Primitives\src\CommunityToolkit.WinUI.Controls.Primitives.csproj</ToolkitPrimitivesSourceProject>
<ToolkitSizersSourceProject>$(RepositoryDirectory)components\Sizers\src\CommunityToolkit.WinUI.Controls.Sizers.csproj</ToolkitSizersSourceProject>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
2 changes: 1 addition & 1 deletion components/Animations/samples/Animations.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Import Project="$(ToolingDirectory)\ToolkitComponent.SampleProject.props" />

<ItemGroup>
<ProjectReference Include="$(ToolkitExtensionSourceProject)"/>
<ProjectReference Include="$(ToolkitExtensionsSourceProject)"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(ToolkitExtensionSourceProject)" />
<ProjectReference Include="$(ToolkitExtensionsSourceProject)" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions components/Animations/src/Expressions/ExpressionFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,8 @@ public ExpressionNodeInfo(OperationType nodeOperationKind, string operationStrin
{ ExpressionNodeType.ColorHsl, new ExpressionNodeInfo(OperationType.Function, "colorhsl") },
{ ExpressionNodeType.ColorRgb, new ExpressionNodeInfo(OperationType.Function, "colorrgb") },
{ ExpressionNodeType.ColorLerp, new ExpressionNodeInfo(OperationType.Function, "colorlerp") },
{ ExpressionNodeType.ColorLerpHsl, new ExpressionNodeInfo(OperationType.Function, "colorhsllerp") },
{ ExpressionNodeType.ColorLerpRgb, new ExpressionNodeInfo(OperationType.Function, "colorrgblerp") },
{ ExpressionNodeType.ColorLerpHsl, new ExpressionNodeInfo(OperationType.Function, "colorlerphsl") },
{ ExpressionNodeType.ColorLerpRgb, new ExpressionNodeInfo(OperationType.Function, "colorlerprgb") },
{ ExpressionNodeType.Concatenate, new ExpressionNodeInfo(OperationType.Function, "concatenate") },
{ ExpressionNodeType.Distance, new ExpressionNodeInfo(OperationType.Function, "distance") },
{ ExpressionNodeType.DistanceSquared, new ExpressionNodeInfo(OperationType.Function, "distancesquared") },
Expand Down
30 changes: 30 additions & 0 deletions components/Animations/src/Implicit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public static void SetAnimations(UIElement element, ImplicitAnimationSet value)
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for the current event.</param>
private static void OnShowAnimationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// See https://github.com/CommunityToolkit/Windows/issues/319
#if HAS_UNO
#pragma warning disable CS0162
return;
#endif

static void OnAnimationsChanged(object sender, EventArgs e)
{
var collection = (ImplicitAnimationSet)sender;
Expand Down Expand Up @@ -160,6 +166,10 @@ static void OnAnimationsChanged(object sender, EventArgs e)
ElementCompositionPreview.SetImplicitShowAnimation(element, null);
}
}

#if HAS_UNO
#pragma warning restore CS0162
#endif
}

/// <summary>
Expand All @@ -169,6 +179,12 @@ static void OnAnimationsChanged(object sender, EventArgs e)
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for the current event.</param>
private static void OnHideAnimationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// See https://github.com/CommunityToolkit/Windows/issues/319
#if HAS_UNO
#pragma warning disable CS0162
return;
#endif

static void OnAnimationsChanged(object sender, EventArgs e)
{
var collection = (ImplicitAnimationSet)sender;
Expand Down Expand Up @@ -200,6 +216,10 @@ static void OnAnimationsChanged(object sender, EventArgs e)
ElementCompositionPreview.SetImplicitHideAnimation(element, null);
}
}

#if HAS_UNO
#pragma warning restore CS0162
#endif
}

/// <summary>
Expand All @@ -209,6 +229,12 @@ static void OnAnimationsChanged(object sender, EventArgs e)
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for the current event.</param>
private static void OnAnimationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// See https://github.com/CommunityToolkit/Windows/issues/319
#if HAS_UNO
#pragma warning disable CS0162
return;
#endif

static void OnAnimationsChanged(object sender, EventArgs e)
{
var collection = (ImplicitAnimationSet)sender;
Expand Down Expand Up @@ -240,5 +266,9 @@ static void OnAnimationsChanged(object sender, EventArgs e)
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = null;
}
}

#if HAS_UNO
#pragma warning restore CS0162
#endif
}
}
1 change: 1 addition & 0 deletions components/Animations/tests/Animations.Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Test_AnimationBuilderStart.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Test_ExpressionFunctions.cs" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion components/Animations/tests/Test_AnimationBuilderStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace AnimationsExperiment.Tests;

[TestClass]
[TestCategory("Test_AnimationBuilderStart")]
[TestCategory(nameof(Test_AnimationBuilderStart))]
public class Test_AnimationBuilderStart : VisualUITestBase
{
[TestMethod]
Expand Down
59 changes: 59 additions & 0 deletions components/Animations/tests/Test_ExpressionFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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.

#if WINUI2
using Windows.UI.Composition;
using Windows.UI.Xaml.Hosting;
#elif WINUI3
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Hosting;
#endif

using System.Numerics;
using CommunityToolkit.Tests;
using CommunityToolkit.Tooling.TestGen;
using CommunityToolkit.WinUI.Animations.Expressions;

namespace AnimationsExperiment.Tests;

[TestClass]
[TestCategory(nameof(Test_ExpressionFunctions))]
public partial class Test_ExpressionFunctions : VisualUITestBase
{
[UIThreadTestMethod]
public void ColorLerpRgb(Grid rootGrid)
{
// See https://github.com/CommunityToolkit/Windows/issues/303
var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor;
var brush = compositor.CreateColorBrush();
var temp = ExpressionFunctions.ColorRgb(255f, 255f, 0f, 0f);
var color = ExpressionFunctions.ColorLerpRgb(temp, temp, 0.5f);

brush.StartAnimation("Color", color);

var visual = compositor.CreateSpriteVisual();
visual.Brush = brush;
visual.RelativeSizeAdjustment = Vector2.One;

ElementCompositionPreview.SetElementChildVisual(rootGrid, visual);
}

[UIThreadTestMethod]
public void ColorLerpHsl(Grid rootGrid)
{
// See https://github.com/CommunityToolkit/Windows/issues/303
var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor;
var brush = compositor.CreateColorBrush();
var temp = ExpressionFunctions.ColorHsl(255f, 255f, 0f);
var color = ExpressionFunctions.ColorLerpHsl(temp, temp, 0.5f);

brush.StartAnimation("Color", color);

var visual = compositor.CreateSpriteVisual();
visual.Brush = brush;
visual.RelativeSizeAdjustment = Vector2.One;

ElementCompositionPreview.SetElementChildVisual(rootGrid, visual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(ToolkitAnimationSourceProject)" />
<ProjectReference Include="$(ToolkitExtensionSourceProject)" />
<ProjectReference Include="$(ToolkitAnimationsSourceProject)" />
<ProjectReference Include="$(ToolkitExtensionsSourceProject)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(ToolkitHelperSourceProject)"/>
<ProjectReference Include="$(ToolkitHelpersSourceProject)"/>
</ItemGroup>

<!-- Sets this up as a toolkit component's source project -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(ToolkitHelperSourceProject)"/>
<ProjectReference Include="$(ToolkitHelpersSourceProject)"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(ToolkitExtensionSourceProject)"/>
<ProjectReference Include="$(ToolkitExtensionsSourceProject)"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(ToolkitExtensionSourceProject)"/>
<ProjectReference Include="$(ToolkitExtensionsSourceProject)"/>
</ItemGroup>

<!-- Sets this up as a toolkit component's source project -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(ToolkitExtensionSourceProject)"/>
<ProjectReference Include="$(ToolkitExtensionsSourceProject)"/>
</ItemGroup>

<!-- Sets this up as a toolkit component's source project -->
Expand Down
4 changes: 0 additions & 4 deletions components/Media/samples/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@
<Project>
<!-- WinUI 2 / UWP -->
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<PackageReference Include="CommunityToolkit.Uwp.Behaviors" Version="8.0.0-beta.2"/>
</ItemGroup>

<!-- WinUI 2 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
<PackageReference Include="CommunityToolkit.Uwp.Behaviors" Version="8.0.0-beta.2"/>
</ItemGroup>

<!-- WinUI 3 / WinAppSdk -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
<PackageReference Include="CommunityToolkit.WinUI.Behaviors" Version="8.0.0-beta.2"/>
</ItemGroup>

<!-- WinUI 3 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
<PackageReference Include="CommunityToolkit.WinUI.Behaviors" Version="8.0.0-beta.2"/>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions components/Media/samples/Media.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

<!-- Sets this up as a toolkit component's sample project -->
<Import Project="$(ToolingDirectory)\ToolkitComponent.SampleProject.props" />

<ItemGroup>
<ProjectReference Include="$(ToolkitBehaviorsSourceProject)" />
</ItemGroup>

<ItemGroup>
<None Remove="Assets\Bloom.jpg" />
Expand Down
11 changes: 9 additions & 2 deletions components/Media/src/Brushes/BackdropGammaTransferBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,14 @@ protected override void OnConnected()
return;
}

var backdrop = Window.Current.Compositor.CreateBackdropBrush();

#if WINUI2
var compositor = Window.Current.Compositor;
#elif WINUI3
var compositor = CompositionTarget.GetCompositorForCurrentThread();
#endif

var backdrop = compositor.CreateBackdropBrush();

// Use a Win2D blur affect applied to a CompositionBackdropBrush.
var graphicsEffect = new GammaTransferEffect
Expand All @@ -370,7 +377,7 @@ protected override void OnConnected()
Source = new CompositionEffectSourceParameter("backdrop")
};

var effectFactory = Window.Current.Compositor.CreateEffectFactory(graphicsEffect, new[]
var effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[]
{
"GammaTransfer.AlphaAmplitude",
"GammaTransfer.AlphaExponent",
Expand Down
10 changes: 8 additions & 2 deletions components/Media/src/Brushes/CanvasBrushBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ protected override void OnConnected()
_graphics.RenderingDeviceReplaced -= CanvasDevice_RenderingDeviceReplaced;
}

_graphics = CanvasComposition.CreateCompositionGraphicsDevice(Window.Current.Compositor, _device);
#if WINUI2
var compositor = Window.Current.Compositor;
#elif WINUI3
var compositor = CompositionTarget.GetCompositorForCurrentThread();
#endif

_graphics = CanvasComposition.CreateCompositionGraphicsDevice(compositor, _device);
_graphics.RenderingDeviceReplaced += CanvasDevice_RenderingDeviceReplaced;

// Delay creating composition resources until they're required.
Expand Down Expand Up @@ -95,7 +101,7 @@ protected override void OnConnected()
}
}

_surfaceBrush = Window.Current.Compositor.CreateSurfaceBrush(surface);
_surfaceBrush = compositor.CreateSurfaceBrush(surface);
_surfaceBrush.Stretch = CompositionStretch.Fill;

CompositionBrush = _surfaceBrush;
Expand Down
Loading

0 comments on commit 30114dd

Please sign in to comment.