Skip to content

Commit

Permalink
feat: Add support for FindElementsInHostCoordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Mar 20, 2020
1 parent 508598b commit 6231d0b
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Windows.UI.Xaml.Controls;
using Uno.Extensions;
using Uno.Disposables;
using Windows.Globalization.DateTimeFormatting;
#if XAMARIN_IOS
using UIKit;
using _View = UIKit.UIView;
Expand Down Expand Up @@ -42,22 +43,50 @@ public static void DisconnectChildrenRecursive(UIElement element)
throw new NotSupportedException();
}

[Uno.NotImplemented]
public static IEnumerable<UIElement> FindElementsInHostCoordinates(Point intersectingPoint, UIElement subtree)
{
throw new NotSupportedException();
}
=> FindElementsInHostCoordinates(intersectingPoint, subtree, false);

[Uno.NotImplemented]
public static IEnumerable<UIElement> FindElementsInHostCoordinates(Rect intersectingRect, UIElement subtree)
{
throw new NotSupportedException();
}

[Uno.NotImplemented]
public static IEnumerable<UIElement> FindElementsInHostCoordinates(Point intersectingPoint, UIElement subtree, bool includeAllElements)
{
throw new NotSupportedException();
if (subtree != null)
{
if(IsElementIntersecting(intersectingPoint, subtree))
{
yield return subtree;
}

foreach (var child in subtree.GetChildren())
{
var canTest = includeAllElements
|| ( child.IsHitTestVisible && child.IsViewHit());

if (child is UIElement uiElement && canTest)
{
if (IsElementIntersecting(intersectingPoint, uiElement))
{
yield return uiElement;
}

foreach (var subChild in FindElementsInHostCoordinates(intersectingPoint, child, includeAllElements))
{
yield return subChild;
}
}
}
}
}

private static bool IsElementIntersecting(Point intersectingPoint, UIElement uiElement)
{
GeneralTransform transformToRoot = uiElement.TransformToVisual(null);
var target = transformToRoot.TransformBounds(uiElement.LayoutSlot);
return target.Contains(intersectingPoint);
}

[Uno.NotImplemented]
Expand Down

0 comments on commit 6231d0b

Please sign in to comment.