|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +#if WINUI2 |
| 6 | +using Windows.UI.Composition; |
| 7 | +using Windows.UI.Xaml.Hosting; |
| 8 | +#elif WINUI3 |
| 9 | +using Microsoft.UI.Composition; |
| 10 | +using Microsoft.UI.Xaml.Hosting; |
| 11 | +#endif |
| 12 | + |
| 13 | +using System.Numerics; |
| 14 | +using CommunityToolkit.Tests; |
| 15 | +using CommunityToolkit.Tooling.TestGen; |
| 16 | +using CommunityToolkit.WinUI.Animations.Expressions; |
| 17 | + |
| 18 | +namespace AnimationsExperiment.Tests; |
| 19 | + |
| 20 | +[TestClass] |
| 21 | +[TestCategory(nameof(Test_ExpressionFunctions))] |
| 22 | +public partial class Test_ExpressionFunctions : VisualUITestBase |
| 23 | +{ |
| 24 | + [UIThreadTestMethod] |
| 25 | + public void ColorLerpRgb(Grid rootGrid) |
| 26 | + { |
| 27 | + // See https://github.com/CommunityToolkit/Windows/issues/303 |
| 28 | + var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor; |
| 29 | + var brush = compositor.CreateColorBrush(); |
| 30 | + var temp = ExpressionFunctions.ColorRgb(255f, 255f, 0f, 0f); |
| 31 | + var color = ExpressionFunctions.ColorLerpRgb(temp, temp, 0.5f); |
| 32 | + |
| 33 | + brush.StartAnimation("Color", color); |
| 34 | + |
| 35 | + var visual = compositor.CreateSpriteVisual(); |
| 36 | + visual.Brush = brush; |
| 37 | + visual.RelativeSizeAdjustment = Vector2.One; |
| 38 | + |
| 39 | + ElementCompositionPreview.SetElementChildVisual(rootGrid, visual); |
| 40 | + } |
| 41 | + |
| 42 | + [UIThreadTestMethod] |
| 43 | + public void ColorLerpHsl(Grid rootGrid) |
| 44 | + { |
| 45 | + // See https://github.com/CommunityToolkit/Windows/issues/303 |
| 46 | + var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor; |
| 47 | + var brush = compositor.CreateColorBrush(); |
| 48 | + var temp = ExpressionFunctions.ColorHsl(255f, 255f, 0f); |
| 49 | + var color = ExpressionFunctions.ColorLerpHsl(temp, temp, 0.5f); |
| 50 | + |
| 51 | + brush.StartAnimation("Color", color); |
| 52 | + |
| 53 | + var visual = compositor.CreateSpriteVisual(); |
| 54 | + visual.Brush = brush; |
| 55 | + visual.RelativeSizeAdjustment = Vector2.One; |
| 56 | + |
| 57 | + ElementCompositionPreview.SetElementChildVisual(rootGrid, visual); |
| 58 | + } |
| 59 | +} |
0 commit comments