Browse Source
Reset LayoutTransformControl matrix when transform is removed
pull/11830/head
Julien Lebosquain
3 years ago
No known key found for this signature in database
GPG Key ID: 1833CAD10ACC46FD
2 changed files with
28 additions and
6 deletions
-
src/Avalonia.Controls/LayoutTransformControl.cs
-
tests/Avalonia.Controls.UnitTests/LayoutTransformControlTests.cs
|
|
|
@ -215,7 +215,7 @@ namespace Avalonia.Controls |
|
|
|
/// <summary>
|
|
|
|
/// Transformation matrix corresponding to _matrixTransform.
|
|
|
|
/// </summary>
|
|
|
|
private Matrix _transformation; |
|
|
|
private Matrix _transformation = Matrix.Identity; |
|
|
|
private IDisposable? _transformChangedEvent; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -256,13 +256,16 @@ namespace Avalonia.Controls |
|
|
|
/// </remarks>
|
|
|
|
private void ApplyLayoutTransform() |
|
|
|
{ |
|
|
|
if (LayoutTransform == null) |
|
|
|
return; |
|
|
|
|
|
|
|
// Get the transform matrix and apply it
|
|
|
|
_transformation = RoundMatrix(LayoutTransform.Value, DecimalsAfterRound); |
|
|
|
var matrix = LayoutTransform is null ? |
|
|
|
Matrix.Identity : |
|
|
|
RoundMatrix(LayoutTransform.Value, DecimalsAfterRound); |
|
|
|
|
|
|
|
if (_transformation == matrix) |
|
|
|
return; |
|
|
|
|
|
|
|
_matrixTransform.Matrix = _transformation; |
|
|
|
_transformation = matrix; |
|
|
|
_matrixTransform.Matrix = matrix; |
|
|
|
|
|
|
|
// New transform means re-layout is necessary
|
|
|
|
InvalidateMeasure(); |
|
|
|
|
|
|
|
@ -169,6 +169,25 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
new Rect(0, 100, 100, 25)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Bounds_On_Transform_Applied_Then_Removed_Are_Correct() |
|
|
|
{ |
|
|
|
using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface); |
|
|
|
|
|
|
|
var control = CreateWithChildAndMeasureAndTransform( |
|
|
|
100, |
|
|
|
25, |
|
|
|
new RotateTransform { Angle = 90 }); |
|
|
|
|
|
|
|
Assert.Equal(new Size(25, 100), control.DesiredSize); |
|
|
|
|
|
|
|
control.LayoutTransform = null; |
|
|
|
control.Measure(Size.Infinity); |
|
|
|
control.Arrange(new Rect(control.DesiredSize)); |
|
|
|
|
|
|
|
Assert.Equal(new Size(100, 25), control.DesiredSize); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Generate_RotateTransform_90_degrees() |
|
|
|
{ |
|
|
|
|