forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AvaloniaUI#7658 from trympet/7657-fix-brush-opacit…
…y-animation fix brush opacity animation
- Loading branch information
1 parent
d535960
commit 5b4f5da
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
54 changes: 54 additions & 0 deletions
54
tests/Avalonia.Animation.UnitTests/BrushTransitionTests.cs
This file contains 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,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Avalonia.Controls; | ||
using Avalonia.Media; | ||
using Xunit; | ||
|
||
namespace Avalonia.Animation.UnitTests | ||
{ | ||
public class BrushTransitionTests | ||
{ | ||
[Fact] | ||
public void SolidColorBrush_Opacity_IsInteroplated() | ||
{ | ||
Test(0, new SolidColorBrush { Opacity = 0 }, new SolidColorBrush { Opacity = 0 }); | ||
Test(0, new SolidColorBrush { Opacity = 0 }, new SolidColorBrush { Opacity = 1 }); | ||
Test(0.5, new SolidColorBrush { Opacity = 0 }, new SolidColorBrush { Opacity = 1 }); | ||
Test(0.5, new SolidColorBrush { Opacity = 0.5 }, new SolidColorBrush { Opacity = 0.5 }); | ||
Test(1, new SolidColorBrush { Opacity = 1 }, new SolidColorBrush { Opacity = 1 }); | ||
// TODO: investigate why this case fails. | ||
//Test2(1, new SolidColorBrush { Opacity = 0 }, new SolidColorBrush { Opacity = 1 }); | ||
} | ||
|
||
[Fact] | ||
public void LinearGradientBrush_Opacity_IsInteroplated() | ||
{ | ||
Test(0, new LinearGradientBrush { Opacity = 0 }, new LinearGradientBrush { Opacity = 0 }); | ||
Test(0, new LinearGradientBrush { Opacity = 0 }, new LinearGradientBrush { Opacity = 1 }); | ||
Test(0.5, new LinearGradientBrush { Opacity = 0 }, new LinearGradientBrush { Opacity = 1 }); | ||
Test(0.5, new LinearGradientBrush { Opacity = 0.5 }, new LinearGradientBrush { Opacity = 0.5 }); | ||
Test(1, new LinearGradientBrush { Opacity = 1 }, new LinearGradientBrush { Opacity = 1 }); | ||
} | ||
|
||
private static void Test(double progress, IBrush oldBrush, IBrush newBrush) | ||
{ | ||
var clock = new TestClock(); | ||
var border = new Border() { Background = oldBrush }; | ||
BrushTransition sut = new BrushTransition | ||
{ | ||
Duration = TimeSpan.FromSeconds(1), | ||
Property = Border.BackgroundProperty | ||
}; | ||
|
||
sut.Apply(border, clock, oldBrush, newBrush); | ||
clock.Pulse(TimeSpan.Zero); | ||
clock.Pulse(sut.Duration * progress); | ||
|
||
Assert.NotNull(border.Background); | ||
Assert.Equal(oldBrush.Opacity + (newBrush.Opacity - oldBrush.Opacity) * progress, border.Background.Opacity); | ||
} | ||
} | ||
} |