Browse Source

Merge pull request #1901 from jkoritzinsky/custom-hittesting

Add in custom hit testing for ImmediateRenderer.
pull/1911/head
Jeremy Koritzinsky 8 years ago
committed by GitHub
parent
commit
ef225f31a8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Avalonia.Controls/Primitives/AdornerLayer.cs
  2. 12
      src/Avalonia.Visuals/Rendering/ICustomSimpleHitTest.cs
  3. 11
      src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs

8
src/Avalonia.Controls/Primitives/AdornerLayer.cs

@ -6,11 +6,12 @@ using System.Collections.Specialized;
using System.Linq; using System.Linq;
using Avalonia.VisualTree; using Avalonia.VisualTree;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Rendering;
namespace Avalonia.Controls.Primitives namespace Avalonia.Controls.Primitives
{ {
// TODO: Need to track position of adorned elements and move the adorner if they move. // TODO: Need to track position of adorned elements and move the adorner if they move.
public class AdornerLayer : Panel public class AdornerLayer : Panel, ICustomSimpleHitTest
{ {
public static AttachedProperty<Visual> AdornedElementProperty = public static AttachedProperty<Visual> AdornedElementProperty =
AvaloniaProperty.RegisterAttached<AdornerLayer, Visual, Visual>("AdornedElement"); AvaloniaProperty.RegisterAttached<AdornerLayer, Visual, Visual>("AdornedElement");
@ -137,6 +138,11 @@ namespace Avalonia.Controls.Primitives
} }
} }
public bool HitTest(Point point)
{
return Children.Any(ctrl => ctrl.TransformedBounds?.Contains(point) == true);
}
private class AdornedElementInfo private class AdornedElementInfo
{ {
public IDisposable Subscription { get; set; } public IDisposable Subscription { get; set; }

12
src/Avalonia.Visuals/Rendering/ICustomSimpleHitTest.cs

@ -0,0 +1,12 @@
namespace Avalonia.Rendering
{
/// <summary>
/// An interface to allow non-templated controls to customize their hit-testing
/// when using a renderer with a simple hit-testing algorithm without a scene graph,
/// such as <see cref="ImmediateRenderer" />
/// </summary>
public interface ICustomSimpleHitTest
{
bool HitTest(Point point);
}
}

11
src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs

@ -200,7 +200,16 @@ namespace Avalonia.Rendering
if (filter?.Invoke(visual) != false) if (filter?.Invoke(visual) != false)
{ {
bool containsPoint = visual.TransformedBounds?.Contains(p) == true; bool containsPoint = false;
if (visual is ICustomSimpleHitTest custom)
{
containsPoint = custom.HitTest(p);
}
else
{
containsPoint = visual.TransformedBounds?.Contains(p) == true;
}
if ((containsPoint || !visual.ClipToBounds) && visual.VisualChildren.Count > 0) if ((containsPoint || !visual.ClipToBounds) && visual.VisualChildren.Count > 0)
{ {

Loading…
Cancel
Save