From d068e1b4fa0d2a94236b4ea659e9ba71a0b60ccf Mon Sep 17 00:00:00 2001 From: amwx Date: Sun, 2 May 2021 18:27:57 -0500 Subject: [PATCH 01/18] Clean fluent light --- .../Accents/AccentColors.xaml | 15 ++ src/Avalonia.Themes.Fluent/Accents/Base.xaml | 8 + .../Accents/BaseLight.xaml | 58 ++++- .../Accents/FluentBaseLight.xaml | 82 +++--- .../Accents/FluentControlResourcesLight.xaml | 242 ++++++++++++------ src/Avalonia.Themes.Fluent/FluentLight.xaml | 1 + 6 files changed, 260 insertions(+), 146 deletions(-) create mode 100644 src/Avalonia.Themes.Fluent/Accents/AccentColors.xaml diff --git a/src/Avalonia.Themes.Fluent/Accents/AccentColors.xaml b/src/Avalonia.Themes.Fluent/Accents/AccentColors.xaml new file mode 100644 index 0000000000..1cf2f7e43d --- /dev/null +++ b/src/Avalonia.Themes.Fluent/Accents/AccentColors.xaml @@ -0,0 +1,15 @@ + diff --git a/src/Avalonia.Themes.Fluent/Accents/Base.xaml b/src/Avalonia.Themes.Fluent/Accents/Base.xaml index 0e34eb3f3b..8597c76998 100644 --- a/src/Avalonia.Themes.Fluent/Accents/Base.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/Base.xaml @@ -22,5 +22,13 @@ 10,6,6,5 20 20 + + + 3 + 5 + + + scaleX(0.125) translateX(-2px) + scaleY(0.125) translateY(-2px) diff --git a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml index 6c8d16ddfa..d25d437e03 100644 --- a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml @@ -2,16 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=netstandard"> - - - #FF0078D7 - #FF005A9E - #FF004275 - #FF002642 - #FF429CE3 - #FF76B9ED - #FFA6D8FF - #FFFFFFFF #33FFFFFF @@ -40,6 +30,9 @@ #33000000 #C50500 + #17000000 + #2E000000 + @@ -135,7 +128,7 @@ - + @@ -150,9 +143,48 @@ - False + + + + + + + + + + + #FFFFFFFF + + + + 374 + 0,2,0,2 + 1 + -1,0,-1,0 + 32 + 64 + 456 + 0 + 1 + 0 + + 12,11,12,12 + 96 + 40 + 758 + + + 0 + + + 0,4,0,4 + + 12,0,12,0 + + + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml index ad23955776..7e048fe029 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml @@ -2,20 +2,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=netstandard"> - #17000000 - #2E000000 - - - - - - - - 3 - 5 - + - 1,1,1,1 + - - #FFFFFFFF - - + - + - + - + - 0 + - + - + - + - + - + - + - 12 + - XamlAutoFontFamily + - + - + - + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml index 5af24f57a8..e569b2a825 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml @@ -28,6 +28,7 @@ + - 1 @@ -53,6 +53,8 @@ + + 1 @@ -100,6 +103,7 @@ + - 21 - 64 - 80 - 240 + 64 1 - 1 - 0,0,0,4 - 2 - 11,5,11,7 - 11,11,11,13 - 11,11,11,13 + 1 + 11,5,11,7 Normal - SemiLight - @@ -147,16 +142,13 @@ - - - @@ -182,10 +174,26 @@ - + 0 + 0,4,0,4 + + 0 + - 0.6 + --> + + 4 0 + 1 @@ -276,7 +284,6 @@ - @@ -286,8 +293,46 @@ 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 - 0 @@ -361,7 +401,7 @@ - + @@ -393,6 +433,10 @@ + + - @@ -417,12 +460,9 @@ - - - @@ -430,11 +470,16 @@ - + @@ -482,6 +527,7 @@ + 4 2 0 - 0,0,0,4 Normal @@ -525,6 +570,8 @@ + 0 1 - - - - @@ -583,6 +626,13 @@ + + 12 @@ -613,16 +663,16 @@ + 8,5,8,7 + - @@ -631,17 +681,14 @@ - - - @@ -651,7 +698,13 @@ - + + + @@ -665,30 +718,35 @@ - - + + - XamlAutoFontFamily 24 - 40 - -25 12,0,12,0 12,0,12,0 SemiLight + + + @@ -704,23 +762,20 @@ - + + 0 - 1 - - - - @@ -729,18 +784,29 @@ - - - - + + + 16 + 8 + + + @@ -794,11 +857,15 @@ - - - 1 32 + + + + @@ -810,7 +877,12 @@ - + + + + + + diff --git a/src/Avalonia.Themes.Fluent/FluentLight.xaml b/src/Avalonia.Themes.Fluent/FluentLight.xaml index 1bc51f655e..31cff6def1 100644 --- a/src/Avalonia.Themes.Fluent/FluentLight.xaml +++ b/src/Avalonia.Themes.Fluent/FluentLight.xaml @@ -1,6 +1,7 @@ + From 7ff30a7d2b57ad6cc29fb871af2959a3c959c324 Mon Sep 17 00:00:00 2001 From: amwx Date: Sun, 2 May 2021 18:28:20 -0500 Subject: [PATCH 02/18] Clean fluent dark --- .../Accents/BaseDark.xaml | 70 +++-- .../Accents/FluentBaseDark.xaml | 84 +++--- .../Accents/FluentControlResourcesDark.xaml | 268 +++++++++++------- src/Avalonia.Themes.Fluent/FluentDark.xaml | 3 +- 4 files changed, 253 insertions(+), 172 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml index fb08b97b47..4c2022e2ce 100644 --- a/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml @@ -2,16 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=netstandard"> - - - #FF0078D7 - #FF005A9E - #FF004275 - #FF002642 - #FF429CE3 - #FF76B9ED - #FFA6D8FF - #FF000000 #33000000 @@ -40,6 +30,9 @@ #33FFFFFF #FFF000 + #18FFFFFF + #30FFFFFF + @@ -135,7 +128,7 @@ - + @@ -150,10 +143,45 @@ - False + + + + + + + + + #FF000000 + + + 374 + 0,2,0,2 + 1 + -1,0,-1,0 + 32 + 64 + 456 + 0 + 1 + 0 + 12,11,12,12 + 96 + 40 + 758 + + + 0 + + 0,4,0,4 + + + 12,0,12,0 + + + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml index 1c65911593..b4d4d93dc4 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml @@ -2,20 +2,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=netstandard"> - #18FFFFFF - #30FFFFFF - - - - - - - - 3 - 5 - + - 1,1,1,1 + + - #FF000000 - - + - + - + - + - 0 + + - + - + - + - + - + - + - 12 + - XamlAutoFontFamily + + - + - + - + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml index ae1fe42031..81ce7dfe1b 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml @@ -28,6 +28,7 @@ + - - 1 + @@ -53,6 +53,8 @@ + 1 @@ -101,6 +103,7 @@ + - 21 64 - 80 - 240 1 1 - 0,0,0,4 - 2 11,5,11,7 - 11,11,11,13 - 11,11,11,13 - Normal - SemiLight + Normal - - + @@ -147,17 +141,14 @@ - - + - - + - - + @@ -182,11 +173,32 @@ - - + + 0 + 0,4,0,4 + + 0 + + + + 4 + 0 + 1 @@ -268,8 +283,7 @@ - - + @@ -279,17 +293,45 @@ 1 - - - 0.6 - 4 - 0 - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 - 0 @@ -363,7 +400,7 @@ - + @@ -395,6 +432,10 @@ + + - @@ -419,12 +459,9 @@ - - - @@ -432,12 +469,17 @@ - - + + @@ -484,6 +526,7 @@ + 4 2 0 - 0,0,0,4 Normal @@ -527,6 +569,8 @@ + 0 1 - - - - @@ -585,6 +625,13 @@ + + 12 @@ -615,16 +662,16 @@ + 8,5,8,7 + - @@ -633,17 +680,14 @@ - - - @@ -654,6 +698,12 @@ + + @@ -667,30 +717,35 @@ - - + + - XamlAutoFontFamily 24 - 40 - -25 12,0,12,0 12,0,12,0 SemiLight - + + + @@ -705,24 +760,21 @@ - - + + + 0 - 1 - - - - @@ -731,20 +783,29 @@ - - - - + 16 + 8 + + + @@ -796,11 +856,14 @@ - - - 1 32 + + + @@ -812,7 +875,10 @@ - + + + + diff --git a/src/Avalonia.Themes.Fluent/FluentDark.xaml b/src/Avalonia.Themes.Fluent/FluentDark.xaml index 74b583a240..dbd25f5a1d 100644 --- a/src/Avalonia.Themes.Fluent/FluentDark.xaml +++ b/src/Avalonia.Themes.Fluent/FluentDark.xaml @@ -1,6 +1,7 @@ + xmlns:sys="clr-namespace:System;assembly=netstandard"> + From d0865f36d7b33a503787ef9b572e5c3304b33759 Mon Sep 17 00:00:00 2001 From: amwx Date: Sun, 2 May 2021 18:28:38 -0500 Subject: [PATCH 03/18] Various controls --- src/Avalonia.Themes.Fluent/Controls/ContextMenu.xaml | 8 +++++++- .../Controls/EmbeddableControlRoot.xaml | 2 +- src/Avalonia.Themes.Fluent/Controls/FlyoutPresenter.xaml | 1 - src/Avalonia.Themes.Fluent/Controls/Menu.xaml | 1 - src/Avalonia.Themes.Fluent/Controls/MenuItem.xaml | 3 +-- src/Avalonia.Themes.Fluent/Controls/Window.xaml | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Controls/ContextMenu.xaml b/src/Avalonia.Themes.Fluent/Controls/ContextMenu.xaml index a4e716c7f6..5110d70a80 100644 --- a/src/Avalonia.Themes.Fluent/Controls/ContextMenu.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/ContextMenu.xaml @@ -1,4 +1,5 @@ diff --git a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml index d25d437e03..e5c0babb80 100644 --- a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml @@ -128,7 +128,6 @@ - @@ -143,8 +142,7 @@ - - + @@ -181,197 +179,5 @@ 12,0,12,0 - - - - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml deleted file mode 100644 index 361f1f9038..0000000000 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml +++ /dev/null @@ -1,444 +0,0 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml deleted file mode 100644 index 36c0feeb6f..0000000000 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml +++ /dev/null @@ -1,446 +0,0 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml index 81ce7dfe1b..a1f423c059 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml @@ -28,17 +28,6 @@ - @@ -53,17 +42,6 @@ - 1 @@ -103,25 +81,6 @@ - 64 @@ -176,94 +135,15 @@ - 0 0,4,0,4 - - 0 - 4 - 0 - + 0 1 @@ -293,10 +173,7 @@ 1 - - - + @@ -310,7 +187,6 @@ - @@ -319,45 +195,19 @@ - - + - - + - - + 1 @@ -399,8 +249,7 @@ - - + @@ -432,24 +281,7 @@ - - + @@ -473,13 +305,7 @@ - - + @@ -526,23 +352,7 @@ - - + 4 2 @@ -569,31 +379,7 @@ - - + 0 1 @@ -626,36 +412,6 @@ - - 12 1 @@ -663,10 +419,6 @@ 8,5,8,7 - @@ -697,12 +449,7 @@ - - + @@ -726,26 +473,13 @@ - - 24 12,0,12,0 12,0,12,0 SemiLight - - - + @@ -763,8 +497,6 @@ - 0 @@ -795,41 +527,6 @@ 16 8 - - @@ -859,11 +556,6 @@ 1 32 - - @@ -878,7 +570,6 @@ - - + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml index e569b2a825..f75af76144 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml @@ -28,18 +28,7 @@ - - + @@ -53,18 +42,7 @@ - - + 1 @@ -103,26 +81,7 @@ - - + 64 1 @@ -152,7 +111,6 @@ - @@ -176,95 +134,16 @@ - 0 0,4,0,4 - - 0 - 4 0 - - + 1 32 @@ -293,12 +172,8 @@ 1 - - - + - @@ -309,8 +184,7 @@ - - + @@ -319,8 +193,7 @@ - - + @@ -328,37 +201,10 @@ - - - - + 1 @@ -400,8 +246,7 @@ - - + @@ -433,25 +278,7 @@ - - - + @@ -474,13 +301,7 @@ - - + @@ -527,23 +348,7 @@ - - + 4 2 @@ -570,31 +375,7 @@ - - + 0 1 @@ -627,36 +408,6 @@ - - 12 1 @@ -664,11 +415,7 @@ 8,5,8,7 - - + @@ -698,13 +445,7 @@ - - - + @@ -726,27 +467,14 @@ - - - + 24 12,0,12,0 12,0,12,0 SemiLight - - - + @@ -763,10 +491,7 @@ - - - + 0 @@ -796,42 +521,7 @@ 16 8 - - - + @@ -860,12 +550,6 @@ 1 32 - - - @@ -881,8 +565,5 @@ - - - From dfa75a6d4f5623d82bf3babe485e04a22d3425b9 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 7 May 2021 23:21:00 +0800 Subject: [PATCH 06/18] fix bug on instances where SCB animation applies a localvalue wrongly. --- .../Animators/SolidColorBrushAnimator.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index a8e618af27..42962e219e 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -41,23 +41,23 @@ namespace Avalonia.Animation.Animators SolidColorBrush finalTarget; var targetVal = control.GetValue(Property); - if (targetVal is null) + + switch (targetVal) { - finalTarget = new SolidColorBrush(Colors.Transparent); - control.SetValue(Property, finalTarget); - } - else if (targetVal is ImmutableSolidColorBrush immutableSolidColorBrush) - { - finalTarget = new SolidColorBrush(immutableSolidColorBrush.Color); - control.SetValue(Property, finalTarget); - } - else if (targetVal is ISolidColorBrush) - { - finalTarget = targetVal as SolidColorBrush; - } - else - { - return Disposable.Empty; + case null: + finalTarget = new SolidColorBrush(Colors.Transparent); + break; + case ImmutableSolidColorBrush immutableSolidColorBrush: + finalTarget = new SolidColorBrush(immutableSolidColorBrush.Color); + break; + case SolidColorBrush target: + finalTarget = target; + break; + case ISolidColorBrush target: + finalTarget = target as SolidColorBrush; + break; + default: + return Disposable.Empty; } if (_colorAnimator == null) From f80709287715d96cf9e3c85493d168b228aec05a Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 8 May 2021 19:58:57 +0800 Subject: [PATCH 07/18] Heavily simplify SCB animator --- .../Animation/Animators/ColorAnimator.cs | 7 ++- .../Animators/SolidColorBrushAnimator.cs | 60 ++----------------- 2 files changed, 11 insertions(+), 56 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/ColorAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/ColorAnimator.cs index 6d1f6c39bd..1686cafeb9 100644 --- a/src/Avalonia.Visuals/Animation/Animators/ColorAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/ColorAnimator.cs @@ -31,6 +31,11 @@ namespace Avalonia.Animation.Animators } public override Color Interpolate(double progress, Color oldValue, Color newValue) + { + return InterpolateCore(progress, oldValue, newValue); + } + + internal static Color InterpolateCore(double progress, Color oldValue, Color newValue) { // normalize sRGB values. var oldA = oldValue.A / 255d; @@ -59,7 +64,7 @@ namespace Avalonia.Animation.Animators var b = oldB + progress * (newB - oldB); // convert back to sRGB in the [0..255] range - a = a * 255d; + a *= 255d; r = OECF_sRGB(r) * 255d; g = OECF_sRGB(g) * 255d; b = OECF_sRGB(b) * 255d; diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 42962e219e..80eb13d2c4 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -8,64 +8,14 @@ namespace Avalonia.Animation.Animators /// /// Animator that handles . /// - public class SolidColorBrushAnimator : Animator + public class SolidColorBrushAnimator : Animator { - private ColorAnimator _colorAnimator; - - private void InitializeColorAnimator() - { - _colorAnimator = new ColorAnimator(); - - foreach (AnimatorKeyFrame keyframe in this) - { - _colorAnimator.Add(keyframe); - } - - _colorAnimator.Property = SolidColorBrush.ColorProperty; - } - - public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable match, Action onComplete) + public override IBrush Interpolate(double progress, IBrush oldValue, IBrush newValue) { - // Preprocess keyframe values to Color if the xaml parser converts them to ISCB. - foreach (var keyframe in this) - { - if (keyframe.Value is ISolidColorBrush colorBrush) - { - keyframe.Value = colorBrush.Color; - } - else - { - return Disposable.Empty; - } - } - - SolidColorBrush finalTarget; - var targetVal = control.GetValue(Property); + if (oldValue is not ISolidColorBrush oldValS || newValue is not ISolidColorBrush newValS) + return Brushes.Transparent; - switch (targetVal) - { - case null: - finalTarget = new SolidColorBrush(Colors.Transparent); - break; - case ImmutableSolidColorBrush immutableSolidColorBrush: - finalTarget = new SolidColorBrush(immutableSolidColorBrush.Color); - break; - case SolidColorBrush target: - finalTarget = target; - break; - case ISolidColorBrush target: - finalTarget = target as SolidColorBrush; - break; - default: - return Disposable.Empty; - } - - if (_colorAnimator == null) - InitializeColorAnimator(); - - return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete); + return new ImmutableSolidColorBrush(ColorAnimator.InterpolateCore(progress, oldValS.Color, newValS.Color)); } - - public override SolidColorBrush Interpolate(double p, SolidColorBrush o, SolidColorBrush n) => null; } } From 8df4a59cbe9c133860a2197f4896c8122c9cf638 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 8 May 2021 21:15:01 +0800 Subject: [PATCH 08/18] dont use "not" c# preview feature --- .../Animation/Animators/SolidColorBrushAnimator.cs | 2 +- src/Avalonia.Visuals/ApiCompatBaseline.txt | 4 +++- src/Avalonia.Visuals/Media/SolidColorBrush.cs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 80eb13d2c4..3ae9b3be5f 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -12,7 +12,7 @@ namespace Avalonia.Animation.Animators { public override IBrush Interpolate(double progress, IBrush oldValue, IBrush newValue) { - if (oldValue is not ISolidColorBrush oldValS || newValue is not ISolidColorBrush newValS) + if (!(oldValue is ISolidColorBrush oldValS) || !(newValue is ISolidColorBrush newValS)) return Brushes.Transparent; return new ImmutableSolidColorBrush(ColorAnimator.InterpolateCore(progress, oldValS.Color, newValS.Color)); diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt index 35ba8f2b19..69a0ea30fa 100644 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -1,4 +1,6 @@ Compat issues with assembly Avalonia.Visuals: +CannotRemoveBaseTypeOrInterface : Type 'Avalonia.Animation.Animators.SolidColorBrushAnimator' does not inherit from base type 'Avalonia.Animation.Animators.Animator' in the implementation but it does in the contract. +MembersMustExist : Member 'public Avalonia.Media.SolidColorBrush Avalonia.Animation.Animators.SolidColorBrushAnimator.Interpolate(System.Double, Avalonia.Media.SolidColorBrush, Avalonia.Media.SolidColorBrush)' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract. CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' is abstract in the implementation but is missing in the contract. CannotSealType : Type 'Avalonia.Media.TextFormatting.GenericTextParagraphProperties' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract. @@ -63,4 +65,4 @@ InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalon InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun, System.Double)' is present in the contract but not in the implementation. MembersMustExist : Member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun, System.Double)' does not exist in the implementation but it does exist in the contract. -Total Issues: 64 +Total Issues: 66 diff --git a/src/Avalonia.Visuals/Media/SolidColorBrush.cs b/src/Avalonia.Visuals/Media/SolidColorBrush.cs index 8e30880489..f390489ed5 100644 --- a/src/Avalonia.Visuals/Media/SolidColorBrush.cs +++ b/src/Avalonia.Visuals/Media/SolidColorBrush.cs @@ -17,8 +17,8 @@ namespace Avalonia.Media static SolidColorBrush() { - Animation.Animation.RegisterAnimator(prop => typeof(IBrush).IsAssignableFrom(prop.PropertyType)); - AffectsRender(ColorProperty); + Animation.Animation.RegisterAnimator(prop => typeof(ISolidColorBrush).IsAssignableFrom(prop.PropertyType)); + AffectsRender(ColorProperty); } /// From 80c276f31e7e1c0ca5fa5eb60a44396f6f1cfe45 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 9 May 2021 00:15:56 +0800 Subject: [PATCH 09/18] Revamp the brush animators to handle future IBrush types. --- src/Avalonia.Animation/Animation.cs | 11 +++ .../Animation/Animators/BaseBrushAnimator.cs | 68 +++++++++++++++++++ .../Animators/SolidColorBrushAnimator.cs | 12 ++-- src/Avalonia.Visuals/Media/Brush.cs | 2 + src/Avalonia.Visuals/Media/SolidColorBrush.cs | 5 +- 5 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs diff --git a/src/Avalonia.Animation/Animation.cs b/src/Avalonia.Animation/Animation.cs index 05142532e9..c42153ec4f 100644 --- a/src/Avalonia.Animation/Animation.cs +++ b/src/Avalonia.Animation/Animation.cs @@ -209,6 +209,17 @@ namespace Avalonia.Animation ( prop => typeof(decimal).IsAssignableFrom(prop.PropertyType), typeof(DecimalAnimator) ), }; + /// + /// Registers a that can handle + /// a value type that matches the specified condition. + /// + /// + /// The condition to which the + /// is to be activated and used. + /// + /// + /// The type of the animator to instantiate. + /// public static void RegisterAnimator(Func condition) where TAnimator : IAnimator { diff --git a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs new file mode 100644 index 0000000000..9576803692 --- /dev/null +++ b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Disposables; +using Avalonia.Logging; +using Avalonia.Media; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles all animations on properties + /// with as their type and + /// redirect them to the properly registered + /// animators in this class. + /// + public class BaseBrushAnimator : Animator + { + private IAnimator _targetAnimator; + + private static readonly List<(Func Match, Type AnimatorType)> _brushAnimators = new(); + + /// + /// Register an that handles a specific + /// 's descendant value type. + /// + /// + /// The condition to which the + /// is to be activated and used. + /// + /// + /// The type of the animator to instantiate. + /// + public static void RegisterBrushAnimator(Func condition) + where TAnimator : IAnimator + { + _brushAnimators.Insert(0, (condition, typeof(TAnimator))); + } + + /// + public override IDisposable Apply(Animation animation, Animatable control, IClock clock, + IObservable match, Action onComplete) + { + foreach (var valueType in _brushAnimators + .Where(valueType => valueType.Match(this[0].Value.GetType()))) + { + _targetAnimator = (IAnimator)Activator.CreateInstance(valueType.AnimatorType); + + foreach (var keyframe in this) + { + _targetAnimator.Add(keyframe); + } + + _targetAnimator.Property = this.Property; + + _targetAnimator.Apply(animation, control, clock, match, onComplete); + } + + Logger.TryGet(LogEventLevel.Error, LogArea.Animations)?.Log( + this, + "The animation's keyframe values didn't match any brush animators registered in BaseBrushAnimator."); + + return Disposable.Empty; + } + + /// + public override IBrush Interpolate(double progress, IBrush oldValue, IBrush newValue) => null; + } +} diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 3ae9b3be5f..9077ef2e6c 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -1,21 +1,19 @@ -using System; -using System.Reactive.Disposables; -using Avalonia.Media; +using Avalonia.Media; using Avalonia.Media.Immutable; namespace Avalonia.Animation.Animators { /// - /// Animator that handles . + /// Animator that handles values. /// public class SolidColorBrushAnimator : Animator { public override IBrush Interpolate(double progress, IBrush oldValue, IBrush newValue) { - if (!(oldValue is ISolidColorBrush oldValS) || !(newValue is ISolidColorBrush newValS)) + if (!(oldValue is ISolidColorBrush oldSCB) || !(newValue is ISolidColorBrush newSCB)) return Brushes.Transparent; - - return new ImmutableSolidColorBrush(ColorAnimator.InterpolateCore(progress, oldValS.Color, newValS.Color)); + + return new ImmutableSolidColorBrush(ColorAnimator.InterpolateCore(progress, oldSCB.Color, newSCB.Color)); } } } diff --git a/src/Avalonia.Visuals/Media/Brush.cs b/src/Avalonia.Visuals/Media/Brush.cs index a19d5af8b7..fb03d19a4e 100644 --- a/src/Avalonia.Visuals/Media/Brush.cs +++ b/src/Avalonia.Visuals/Media/Brush.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using Avalonia.Animation; +using Avalonia.Animation.Animators; namespace Avalonia.Media { @@ -21,6 +22,7 @@ namespace Avalonia.Media static Brush() { + Animation.Animation.RegisterAnimator(prop => typeof(IBrush).IsAssignableFrom(prop.PropertyType)); AffectsRender(OpacityProperty); } diff --git a/src/Avalonia.Visuals/Media/SolidColorBrush.cs b/src/Avalonia.Visuals/Media/SolidColorBrush.cs index f390489ed5..32663bb8eb 100644 --- a/src/Avalonia.Visuals/Media/SolidColorBrush.cs +++ b/src/Avalonia.Visuals/Media/SolidColorBrush.cs @@ -1,4 +1,3 @@ -using Avalonia.Animation; using Avalonia.Animation.Animators; using Avalonia.Media.Immutable; @@ -17,8 +16,8 @@ namespace Avalonia.Media static SolidColorBrush() { - Animation.Animation.RegisterAnimator(prop => typeof(ISolidColorBrush).IsAssignableFrom(prop.PropertyType)); - AffectsRender(ColorProperty); + BaseBrushAnimator.RegisterBrushAnimator(match => typeof(ISolidColorBrush).IsAssignableFrom(match)); + AffectsRender(ColorProperty); } /// From 72ae35c9ea61745e238e7aa770bc59e5d337ea61 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 9 May 2021 00:16:49 +0800 Subject: [PATCH 10/18] return after applying the target animator in BaseBrushAnimator.cs --- src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs index 9576803692..30162999b5 100644 --- a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs @@ -52,7 +52,7 @@ namespace Avalonia.Animation.Animators _targetAnimator.Property = this.Property; - _targetAnimator.Apply(animation, control, clock, match, onComplete); + return _targetAnimator.Apply(animation, control, clock, match, onComplete); } Logger.TryGet(LogEventLevel.Error, LogArea.Animations)?.Log( From da907379054ab2d6170f8cfcc5905e7026131fe4 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 9 May 2021 00:22:25 +0800 Subject: [PATCH 11/18] revert to non preview feature again --- src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs index 30162999b5..c9a7ad9cba 100644 --- a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs @@ -17,7 +17,7 @@ namespace Avalonia.Animation.Animators { private IAnimator _targetAnimator; - private static readonly List<(Func Match, Type AnimatorType)> _brushAnimators = new(); + private static readonly List<(Func Match, Type AnimatorType)> _brushAnimators = new List<(Func Match, Type AnimatorType)>(); /// /// Register an that handles a specific From 77361a069fa5289b7efb7a40f0f52609c38790e0 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 8 May 2021 22:29:24 -0400 Subject: [PATCH 12/18] Theme loading benchmark --- .../Themes/ThemeBenchmark.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/Avalonia.Benchmarks/Themes/ThemeBenchmark.cs diff --git a/tests/Avalonia.Benchmarks/Themes/ThemeBenchmark.cs b/tests/Avalonia.Benchmarks/Themes/ThemeBenchmark.cs new file mode 100644 index 0000000000..79a11d0cea --- /dev/null +++ b/tests/Avalonia.Benchmarks/Themes/ThemeBenchmark.cs @@ -0,0 +1,63 @@ +using System; + +using Avalonia.Controls; +using Avalonia.Markup.Xaml.Styling; +using Avalonia.Shared.PlatformSupport; +using Avalonia.Styling; +using Avalonia.UnitTests; + +using BenchmarkDotNet.Attributes; + +namespace Avalonia.Benchmarks.Themes +{ + [MemoryDiagnoser] + public class ThemeBenchmark : IDisposable + { + private IDisposable _app; + + public ThemeBenchmark() + { + AssetLoader.RegisterResUriParsers(); + + _app = UnitTestApplication.Start(TestServices.StyledWindow.With(theme: () => null)); + // Add empty style to override it later + UnitTestApplication.Current.Styles.Add(new Style()); + } + + [Benchmark] + [Arguments("avares://Avalonia.Themes.Fluent/FluentDark.xaml")] + [Arguments("avares://Avalonia.Themes.Fluent/FluentLight.xaml")] + public bool InitFluentTheme(string themeUri) + { + UnitTestApplication.Current.Styles[0] = new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks")) + { + Source = new Uri(themeUri) + }; + return ((IResourceHost)UnitTestApplication.Current).TryGetResource("SystemAccentColor", out _); + } + + [Benchmark] + [Arguments("avares://Avalonia.Themes.Default/Accents/BaseLight.xaml")] + [Arguments("avares://Avalonia.Themes.Default/Accents/BaseDark.xaml")] + public bool InitDefaultTheme(string themeUri) + { + UnitTestApplication.Current.Styles[0] = new Styles + { + new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks")) + { + Source = new Uri(themeUri) + }, + new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks")) + { + Source = new Uri("avares://Avalonia.Themes.Default/DefaultTheme.xaml") + } + }; + return ((IResourceHost)UnitTestApplication.Current).TryGetResource("ThemeAccentColor", out _); + } + + public void Dispose() + { + _app.Dispose(); + } + } +} From b06daeb9cd40a30ae3ca45b331bd4bf928783557 Mon Sep 17 00:00:00 2001 From: amwx Date: Sat, 8 May 2021 22:32:30 -0500 Subject: [PATCH 13/18] Remove commented line --- src/Avalonia.Themes.Fluent/FluentDark.xaml | 1 - src/Avalonia.Themes.Fluent/FluentLight.xaml | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/FluentDark.xaml b/src/Avalonia.Themes.Fluent/FluentDark.xaml index c54b5c5e7d..50b12efd78 100644 --- a/src/Avalonia.Themes.Fluent/FluentDark.xaml +++ b/src/Avalonia.Themes.Fluent/FluentDark.xaml @@ -4,7 +4,6 @@ - diff --git a/src/Avalonia.Themes.Fluent/FluentLight.xaml b/src/Avalonia.Themes.Fluent/FluentLight.xaml index b2cb04163c..feb043c5f3 100644 --- a/src/Avalonia.Themes.Fluent/FluentLight.xaml +++ b/src/Avalonia.Themes.Fluent/FluentLight.xaml @@ -4,7 +4,6 @@ - From d084cf8fc7d2bf35fcf387eac3bf4b9f17cdbc9a Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 10 May 2021 14:49:54 +0100 Subject: [PATCH 14/18] dont break api. --- src/Avalonia.Animation/AnimationInstance`1.cs | 2 +- .../Animators/Animator`1.cs | 2 +- .../Animators/SolidColorBrushAnimator.cs | 21 ++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Animation/AnimationInstance`1.cs b/src/Avalonia.Animation/AnimationInstance`1.cs index 6f601a3e13..77547451bb 100644 --- a/src/Avalonia.Animation/AnimationInstance`1.cs +++ b/src/Avalonia.Animation/AnimationInstance`1.cs @@ -12,7 +12,7 @@ namespace Avalonia.Animation /// Handles interpolation and time-related functions /// for keyframe animations. /// - internal class AnimationInstance : SingleSubscriberObservableBase + internal class AnimationInstance : SingleSubscriberObservableBase { private T _lastInterpValue; private T _firstKFValue; diff --git a/src/Avalonia.Animation/Animators/Animator`1.cs b/src/Avalonia.Animation/Animators/Animator`1.cs index 0660440e30..679c879935 100644 --- a/src/Avalonia.Animation/Animators/Animator`1.cs +++ b/src/Avalonia.Animation/Animators/Animator`1.cs @@ -116,7 +116,7 @@ namespace Avalonia.Animation.Animators clock ?? control.Clock ?? Clock.GlobalClock, onComplete, InterpolationHandler); - return control.Bind((AvaloniaProperty)Property, instance, BindingPriority.Animation); + return control.Bind(Property, instance, BindingPriority.Animation); } /// diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 9077ef2e6c..dd1580e3b3 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -1,4 +1,5 @@ -using Avalonia.Media; +using System; +using Avalonia.Media; using Avalonia.Media.Immutable; namespace Avalonia.Animation.Animators @@ -6,14 +7,20 @@ namespace Avalonia.Animation.Animators /// /// Animator that handles values. /// - public class SolidColorBrushAnimator : Animator + public class ISolidColorBrushAnimator : Animator { - public override IBrush Interpolate(double progress, IBrush oldValue, IBrush newValue) + public override ISolidColorBrush Interpolate(double progress, ISolidColorBrush oldValue, ISolidColorBrush newValue) { - if (!(oldValue is ISolidColorBrush oldSCB) || !(newValue is ISolidColorBrush newSCB)) - return Brushes.Transparent; - - return new ImmutableSolidColorBrush(ColorAnimator.InterpolateCore(progress, oldSCB.Color, newSCB.Color)); + return new ImmutableSolidColorBrush(ColorAnimator.InterpolateCore(progress, oldValue.Color, newValue.Color)); + } + } + + [Obsolete] + public class SolidColorBrushAnimator : Animator + { + public override SolidColorBrush Interpolate(double progress, SolidColorBrush oldValue, SolidColorBrush newValue) + { + return new SolidColorBrush(ColorAnimator.InterpolateCore(progress, oldValue.Color, newValue.Color)); } } } From 545253290ed35aa05b858e99a98c466bf5585f92 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 10 May 2021 14:52:46 +0100 Subject: [PATCH 15/18] register new brush animator. --- src/Avalonia.Visuals/Media/SolidColorBrush.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Media/SolidColorBrush.cs b/src/Avalonia.Visuals/Media/SolidColorBrush.cs index 32663bb8eb..fd94cbd214 100644 --- a/src/Avalonia.Visuals/Media/SolidColorBrush.cs +++ b/src/Avalonia.Visuals/Media/SolidColorBrush.cs @@ -16,7 +16,7 @@ namespace Avalonia.Media static SolidColorBrush() { - BaseBrushAnimator.RegisterBrushAnimator(match => typeof(ISolidColorBrush).IsAssignableFrom(match)); + BaseBrushAnimator.RegisterBrushAnimator(match => typeof(ISolidColorBrush).IsAssignableFrom(match)); AffectsRender(ColorProperty); } From c6f248a1e5ade8744440aa4acbc2094afbdad9f7 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 10 May 2021 14:55:16 +0100 Subject: [PATCH 16/18] fix api compat --- src/Avalonia.Visuals/ApiCompatBaseline.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt index 69a0ea30fa..35ba8f2b19 100644 --- a/src/Avalonia.Visuals/ApiCompatBaseline.txt +++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt @@ -1,6 +1,4 @@ Compat issues with assembly Avalonia.Visuals: -CannotRemoveBaseTypeOrInterface : Type 'Avalonia.Animation.Animators.SolidColorBrushAnimator' does not inherit from base type 'Avalonia.Animation.Animators.Animator' in the implementation but it does in the contract. -MembersMustExist : Member 'public Avalonia.Media.SolidColorBrush Avalonia.Animation.Animators.SolidColorBrushAnimator.Interpolate(System.Double, Avalonia.Media.SolidColorBrush, Avalonia.Media.SolidColorBrush)' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract. CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' is abstract in the implementation but is missing in the contract. CannotSealType : Type 'Avalonia.Media.TextFormatting.GenericTextParagraphProperties' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract. @@ -65,4 +63,4 @@ InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalon InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun)' is present in the implementation but not in the contract. InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun, System.Double)' is present in the contract but not in the implementation. MembersMustExist : Member 'public Avalonia.Platform.IGlyphRunImpl Avalonia.Platform.IPlatformRenderInterface.CreateGlyphRun(Avalonia.Media.GlyphRun, System.Double)' does not exist in the implementation but it does exist in the contract. -Total Issues: 66 +Total Issues: 64 From e63e00f7dde218280785c61689cabb83a27d606a Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Mon, 10 May 2021 22:06:07 +0800 Subject: [PATCH 17/18] remove linq --- .../Animation/Animators/BaseBrushAnimator.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs index c9a7ad9cba..508891fd72 100644 --- a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reactive.Disposables; using Avalonia.Logging; using Avalonia.Media; @@ -17,7 +16,8 @@ namespace Avalonia.Animation.Animators { private IAnimator _targetAnimator; - private static readonly List<(Func Match, Type AnimatorType)> _brushAnimators = new List<(Func Match, Type AnimatorType)>(); + private static readonly List<(Func Match, Type AnimatorType)> _brushAnimators = + new List<(Func Match, Type AnimatorType)>(); /// /// Register an that handles a specific @@ -35,14 +35,15 @@ namespace Avalonia.Animation.Animators { _brushAnimators.Insert(0, (condition, typeof(TAnimator))); } - + /// public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable match, Action onComplete) { - foreach (var valueType in _brushAnimators - .Where(valueType => valueType.Match(this[0].Value.GetType()))) + foreach (var valueType in _brushAnimators) { + if (!valueType.Match(this[0].Value.GetType())) continue; + _targetAnimator = (IAnimator)Activator.CreateInstance(valueType.AnimatorType); foreach (var keyframe in this) From 472e179e41e7f108baa398fec043d516a0e0a743 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 10 May 2021 16:22:54 +0100 Subject: [PATCH 18/18] no boxing required. --- src/Avalonia.Animation/AnimationInstance`1.cs | 2 +- src/Avalonia.Animation/Animators/Animator`1.cs | 8 +++++++- .../Animation/Animators/SolidColorBrushAnimator.cs | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Animation/AnimationInstance`1.cs b/src/Avalonia.Animation/AnimationInstance`1.cs index 77547451bb..6f601a3e13 100644 --- a/src/Avalonia.Animation/AnimationInstance`1.cs +++ b/src/Avalonia.Animation/AnimationInstance`1.cs @@ -12,7 +12,7 @@ namespace Avalonia.Animation /// Handles interpolation and time-related functions /// for keyframe animations. /// - internal class AnimationInstance : SingleSubscriberObservableBase + internal class AnimationInstance : SingleSubscriberObservableBase { private T _lastInterpValue; private T _firstKFValue; diff --git a/src/Avalonia.Animation/Animators/Animator`1.cs b/src/Avalonia.Animation/Animators/Animator`1.cs index 679c879935..d784227620 100644 --- a/src/Avalonia.Animation/Animators/Animator`1.cs +++ b/src/Avalonia.Animation/Animators/Animator`1.cs @@ -104,6 +104,11 @@ namespace Avalonia.Animation.Animators throw new Exception("Index time is out of keyframe time range."); } + public virtual IDisposable BindAnimation(Animatable control, IObservable instance) + { + return control.Bind((AvaloniaProperty)Property, instance, BindingPriority.Animation); + } + /// /// Runs the KeyFrames Animation. /// @@ -116,7 +121,8 @@ namespace Avalonia.Animation.Animators clock ?? control.Clock ?? Clock.GlobalClock, onComplete, InterpolationHandler); - return control.Bind(Property, instance, BindingPriority.Animation); + + return BindAnimation(control, instance); } /// diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index dd1580e3b3..cec96fecf8 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -1,4 +1,5 @@ using System; +using Avalonia.Data; using Avalonia.Media; using Avalonia.Media.Immutable; @@ -13,6 +14,11 @@ namespace Avalonia.Animation.Animators { return new ImmutableSolidColorBrush(ColorAnimator.InterpolateCore(progress, oldValue.Color, newValue.Color)); } + + public override IDisposable BindAnimation(Animatable control, IObservable instance) + { + return control.Bind((AvaloniaProperty)Property, instance, BindingPriority.Animation); + } } [Obsolete]