Browse Source
Fixed TransformGroup.Children collection changes not changing TransformGroup.Value (#19525)
pull/19529/head
Tom Edwards
9 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
43 additions and
9 deletions
-
src/Avalonia.Base/Media/TransformGroup.cs
-
tests/Avalonia.Base.UnitTests/Media/TransformOperationsTests.cs
|
|
|
@ -20,12 +20,14 @@ namespace Avalonia.Media |
|
|
|
Justification = "Collection properties shouldn't be set with SetCurrentValue.")] |
|
|
|
public TransformGroup() |
|
|
|
{ |
|
|
|
_childTransformChangedHandler = (_, _) => |
|
|
|
{ |
|
|
|
_lastMatrix = null; |
|
|
|
RaiseChanged(); |
|
|
|
}; |
|
|
|
Children = new Transforms(); |
|
|
|
_childTransformChangedHandler = (_, _) => OnTransformInvalidated(); |
|
|
|
Children = []; |
|
|
|
} |
|
|
|
|
|
|
|
private void OnTransformInvalidated() |
|
|
|
{ |
|
|
|
_lastMatrix = null; |
|
|
|
RaiseChanged(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -79,10 +81,20 @@ namespace Avalonia.Media |
|
|
|
// Ensure reset behavior is Remove
|
|
|
|
newTransforms.ResetBehavior = ResetBehavior.Remove; |
|
|
|
_childrenNotificationSubscription = newTransforms.ForEachItem( |
|
|
|
(tr) => tr.Changed += _childTransformChangedHandler, |
|
|
|
(tr) => tr.Changed -= _childTransformChangedHandler, |
|
|
|
() => { }); |
|
|
|
added: (tr) => |
|
|
|
{ |
|
|
|
tr.Changed += _childTransformChangedHandler; |
|
|
|
OnTransformInvalidated(); |
|
|
|
}, |
|
|
|
removed: (tr) => |
|
|
|
{ |
|
|
|
tr.Changed -= _childTransformChangedHandler; |
|
|
|
OnTransformInvalidated(); |
|
|
|
}, |
|
|
|
reset: () => { }); |
|
|
|
} |
|
|
|
|
|
|
|
OnTransformInvalidated(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Media.Transformation; |
|
|
|
using Avalonia.Utilities; |
|
|
|
using Xunit; |
|
|
|
@ -264,6 +265,27 @@ namespace Avalonia.Base.UnitTests.Media |
|
|
|
AssertMatrix(interpolated_100.Value, scaleX: 0.5, scaleY: 0.5, translateX: 50, translateY: 50); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TransformGroup_Invalidates_When_Child_Collection_Changes() |
|
|
|
{ |
|
|
|
var group = new TransformGroup(); |
|
|
|
var transform = new TranslateTransform(10, 0); |
|
|
|
|
|
|
|
Assert.Equal(Matrix.Identity, group.Value); |
|
|
|
|
|
|
|
group.Children.Add(transform); |
|
|
|
|
|
|
|
Assert.NotEqual(Matrix.Identity, group.Value); |
|
|
|
|
|
|
|
group.Children.Clear(); |
|
|
|
|
|
|
|
Assert.Equal(Matrix.Identity, group.Value); |
|
|
|
|
|
|
|
group.Children = [transform]; |
|
|
|
|
|
|
|
Assert.NotEqual(Matrix.Identity, group.Value); |
|
|
|
} |
|
|
|
|
|
|
|
private static void AssertMatrix(Matrix matrix, double? angle = null, double? scaleX = null, double? scaleY = null, double? translateX = null, double? translateY = null) |
|
|
|
{ |
|
|
|
Assert.True(Matrix.TryDecomposeTransform(matrix, out var composed)); |
|
|
|
|