123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System;
- using System.Linq;
- using Avalonia.Controls;
- using Avalonia.Layout;
- using Avalonia.Media;
- using Avalonia.Rendering;
- using Avalonia.UnitTests;
- using Avalonia.VisualTree;
- using Xunit;
- namespace Avalonia.Base.UnitTests.VisualTree
- {
- public class VisualExtensions_GetVisualsAt
- {
- [Fact]
- public void Should_Find_Control()
- {
- using (TestApplication())
- {
- Border target;
- var root = new TestRoot
- {
- Width = 200,
- Height = 200,
- Child = new StackPanel
- {
- Background = Brushes.White,
- Children =
- {
- (target = new Border
- {
- Width = 100,
- Height = 200,
- Background = Brushes.Red,
- }),
- new Border
- {
- Width = 100,
- Height = 200,
- Background = Brushes.Green,
- }
- },
- Orientation = Orientation.Horizontal,
- }
- };
- root.Renderer = new DeferredRenderer((IRenderRoot)root, null);
- root.Measure(Size.Infinity);
- root.Arrange(new Rect(root.DesiredSize));
- var result = target.GetVisualsAt(new Point(50, 50));
- Assert.Same(target, result.Single());
- }
- }
- [Fact]
- public void Should_Not_Find_Sibling_Control()
- {
- using (TestApplication())
- {
- Border target;
- var root = new TestRoot
- {
- Width = 200,
- Height = 200,
- Child = new StackPanel
- {
- Background = Brushes.White,
- Children =
- {
- (target = new Border
- {
- Width = 100,
- Height = 200,
- Background = Brushes.Red,
- }),
- new Border
- {
- Width = 100,
- Height = 200,
- Background = Brushes.Green,
- }
- },
- Orientation = Orientation.Horizontal,
- }
- };
- root.Renderer = new DeferredRenderer((IRenderRoot)root, null);
- root.Measure(Size.Infinity);
- root.Arrange(new Rect(root.DesiredSize));
- var result = target.GetVisualsAt(new Point(150, 50));
- Assert.Empty(result);
- }
- }
- private static IDisposable TestApplication()
- {
- return UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);
- }
- }
- }
|