-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include Adorners in matrix calculations in VisualExtensions
- Loading branch information
Showing
6 changed files
with
108 additions
and
32 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Avalonia.Metadata; | ||
|
||
namespace Avalonia.Controls; | ||
|
||
[PrivateApi] | ||
public class AdornerLayerBase | ||
{ | ||
/// <summary> | ||
/// Allows for getting and setting of the adorned element. | ||
/// </summary> | ||
public static readonly AttachedProperty<Visual?> AdornedElementProperty = | ||
AvaloniaProperty.RegisterAttached<AdornerLayerBase, Visual, Visual?>("AdornedElement"); | ||
|
||
public static Visual? GetAdornedElement(Visual adorner) | ||
{ | ||
return adorner.GetValue(AdornedElementProperty); | ||
} | ||
|
||
public static void SetAdornedElement(Visual adorner, Visual? adorned) | ||
{ | ||
adorner.SetValue(AdornedElementProperty, adorned); | ||
} | ||
} |
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,9 @@ | ||
using Avalonia.Metadata; | ||
|
||
namespace Avalonia.Controls; | ||
|
||
[PrivateApi] | ||
[NotClientImplementable] | ||
public interface IAdornerLayer | ||
{ | ||
} |
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
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
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
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,34 @@ | ||
using Avalonia.Controls.Primitives; | ||
using Avalonia.UnitTests; | ||
using Xunit; | ||
|
||
namespace Avalonia.Controls.UnitTests; | ||
|
||
public class AdornerLayerTests : ScopedTestBase | ||
{ | ||
[Fact] | ||
public void Adorners_Include_Adorned_Elements_In_Transform_Visual() | ||
{ | ||
var button = new Button() | ||
{ | ||
Margin = new Thickness(100, 100) | ||
}; | ||
var root = new TestRoot() | ||
{ | ||
Child = new VisualLayerManager() | ||
{ | ||
Child = button | ||
} | ||
}; | ||
var adorner = new Border(); | ||
|
||
var adornerLayer = AdornerLayer.GetAdornerLayer(button); | ||
adornerLayer.Children.Add(adorner); | ||
AdornerLayer.SetAdornedElement(adorner, button); | ||
|
||
root.LayoutManager.ExecuteInitialLayoutPass(); | ||
|
||
var translatedPoint = root.TranslatePoint(new Point(100, 100), adorner); | ||
Assert.Equal(new Point(0, 0), translatedPoint); | ||
} | ||
} |