Browse Source

More `ContainsExclusive`

pull/8599/head
Evgeny Gorbovoy 4 years ago
parent
commit
1c1499c399
  1. 4
      src/Avalonia.Base/Rendering/SceneGraph/RectangleNode.cs
  2. 6
      tests/Avalonia.Base.UnitTests/Rendering/CompositorHitTestingTests.cs
  3. 10
      tests/Avalonia.Base.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs

4
src/Avalonia.Base/Rendering/SceneGraph/RectangleNode.cs

@ -103,13 +103,13 @@ namespace Avalonia.Rendering.SceneGraph
if (Brush != null) if (Brush != null)
{ {
var rect = Rect.Rect.Inflate((Pen?.Thickness / 2) ?? 0); var rect = Rect.Rect.Inflate((Pen?.Thickness / 2) ?? 0);
return rect.Contains(p); return rect.ContainsExclusive(p);
} }
else else
{ {
var borderRect = Rect.Rect.Inflate((Pen?.Thickness / 2) ?? 0); var borderRect = Rect.Rect.Inflate((Pen?.Thickness / 2) ?? 0);
var emptyRect = Rect.Rect.Deflate((Pen?.Thickness / 2) ?? 0); var emptyRect = Rect.Rect.Deflate((Pen?.Thickness / 2) ?? 0);
return borderRect.Contains(p) && !emptyRect.Contains(p); return borderRect.ContainsExclusive(p) && !emptyRect.ContainsExclusive(p);
} }
} }

6
tests/Avalonia.Base.UnitTests/Rendering/CompositorHitTestingTests.cs

@ -414,7 +414,7 @@ public class CompositorHitTestingTests : CompositorTestsBase
{ {
using (var s = new CompositorServices(new Size(200, 200))) using (var s = new CompositorServices(new Size(200, 200)))
{ {
Rectangle targetRectangle; Border targetRectangle;
var stackPanel = new StackPanel var stackPanel = new StackPanel
{ {
@ -422,8 +422,8 @@ public class CompositorHitTestingTests : CompositorTestsBase
HorizontalAlignment = HorizontalAlignment.Left, HorizontalAlignment = HorizontalAlignment.Left,
Children = Children =
{ {
new Rectangle { Width = 10, Height = 10, Fill= Brushes.Red}, new Border { Width = 10, Height = 10, Background= Brushes.Red},
{ targetRectangle = new Rectangle { Width = 10, Height = 10, Fill = Brushes.Green} } { targetRectangle = new Border { Width = 10, Height = 10, Background = Brushes.Green} }
} }
}; };

10
tests/Avalonia.Base.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs

@ -542,11 +542,11 @@ namespace Avalonia.Base.UnitTests.Rendering
{ {
using (TestApplication()) using (TestApplication())
{ {
Rectangle targetRectangle; Border targetRectangle;
var root = new TestRoot var root = new TestRoot
{ {
Width = 300, Width = 50,
Height = 200, Height = 200,
Child = new StackPanel Child = new StackPanel
{ {
@ -554,8 +554,8 @@ namespace Avalonia.Base.UnitTests.Rendering
HorizontalAlignment = HorizontalAlignment.Left, HorizontalAlignment = HorizontalAlignment.Left,
Children = Children =
{ {
new Rectangle { Width = 10, Height = 10, Fill = Brushes.Red}, new Border { Width = 50, Height = 50, Background = Brushes.Red},
{ targetRectangle = new Rectangle { Width = 10, Height = 10, Fill = Brushes.Green} } { targetRectangle = new Border { Width = 50, Height = 50, Background = Brushes.Green} }
} }
} }
}; };
@ -564,7 +564,7 @@ namespace Avalonia.Base.UnitTests.Rendering
root.Measure(Size.Infinity); root.Measure(Size.Infinity);
root.Arrange(new Rect(root.DesiredSize)); root.Arrange(new Rect(root.DesiredSize));
var result = root.Renderer.HitTest(new Point(5, 10), root, null); var result = root.Renderer.HitTest(new Point(25, 50), root, null);
Assert.Equal(new[] { targetRectangle }, result); Assert.Equal(new[] { targetRectangle }, result);
} }
} }

Loading…
Cancel
Save