Skip to content

Commit

Permalink
feat: Add support of managed SCP for coordinates computations
Browse files Browse the repository at this point in the history
  • Loading branch information
David authored and dr1rrb committed Mar 10, 2021
1 parent 2b00bcd commit 17ca9d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ScrollViewer()
{
DefaultStyleKey = typeof(ScrollViewer);

#if !__SKIA__
#if !UNO_HAS_MANAGED_SCROLL_PRESENTER
// On Skia, the Scrolling is managed by the ScrollContentPresenter (as UWP), which is flagged as IsScrollPort.
// Note: We should still add support for the zoom factor ... which is not yet supported on Skia.
// Note 2: This as direct consequences in UIElement.GetTransform and VisualTreeHelper.SearchDownForTopMostElementAt
Expand Down Expand Up @@ -1266,7 +1266,7 @@ private void Update(bool isIntermediate)

UpdatePartial(isIntermediate);

#if !__SKIA__
#if !UNO_HAS_MANAGED_SCROLL_PRESENTER
// Effective viewport support
ScrollOffsets = new Point(_pendingHorizontalOffset, _pendingVerticalOffset);
InvalidateViewport();
Expand Down
10 changes: 6 additions & 4 deletions src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ internal static IReadOnlyList<_View> ClearChildren(UIElement view)
var children = view.ChildrenShadow.ToList();
children.ForEach(v => v.RemoveFromSuperview());

return children;
return children;
#elif UNO_REFERENCE_API
var children = GetChildren<_View>(view).ToList();
view.ClearChildren();
Expand Down Expand Up @@ -348,7 +348,7 @@ private static (UIElement? element, Branch? stale) SearchDownForTopMostElementAt
renderingBounds = parentToElement.Transform(renderingBounds);
}

#if !__SKIA__
#if !UNO_HAS_MANAGED_SCROLL_PRESENTER
// On Skia, the Scrolling is managed by the ScrollContentPresenter (as UWP), which is flagged as IsScrollPort.
// Note: We should still add support for the zoom factor ... which is not yet supported on Skia.
if (element is ScrollViewer sv)
Expand All @@ -368,11 +368,13 @@ private static (UIElement? element, Branch? stale) SearchDownForTopMostElementAt
}
else
#endif
#if !__MACOS__ // On macOS the SCP is using RenderTransforms for scrolling which has already been included.
if (element.IsScrollPort)
{
posRelToElement.X += element.ScrollOffsets.X;
posRelToElement.Y += element.ScrollOffsets.Y;
}
#endif

TRACE($"- layoutSlot: {layoutSlot.ToDebugString()}");
TRACE($"- renderBounds (relative to element): {renderingBounds.ToDebugString()}");
Expand Down Expand Up @@ -566,7 +568,7 @@ public void Deconstruct(out UIElement root, out UIElement leaf)
}

/// <summary>
///
///
/// </summary>
/// <remarks>This method will pass through native element but will enumerate only UIElements</remarks>
/// <returns></returns>
Expand All @@ -585,7 +587,7 @@ public IEnumerable<UIElement> EnumerateLeafToRoot()
}

yield return current;
}
}
}

public override string ToString() => $"Root={Root.GetDebugName()} | Leaf={Leaf.GetDebugName()}";
Expand Down
4 changes: 3 additions & 1 deletion src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ internal static Matrix3x2 GetTransform(UIElement from, UIElement to)
offsetY = layoutSlot.Y;
}

#if !__SKIA__
#if !UNO_HAS_MANAGED_SCROLL_PRESENTER
// On Skia, the Scrolling is managed by the ScrollContentPresenter (as UWP), which is flagged as IsScrollPort.
// Note: We should still add support for the zoom factor ... which is not yet supported on Skia.
if (elt is ScrollViewer sv)
Expand All @@ -261,11 +261,13 @@ internal static Matrix3x2 GetTransform(UIElement from, UIElement to)
}
else
#endif
#if !__MACOS__ // On macOS the SCP is using RenderTransforms for scrolling which has already been included.
if (elt.IsScrollPort) // Custom scroller
{
offsetX -= elt.ScrollOffsets.X;
offsetY -= elt.ScrollOffsets.Y;
}
#endif

logInfoString?.Append($"{elt}: ({offsetX}, {offsetY}), ");
} while (elt.TryGetParentUIElementForTransformToVisual(out elt, ref offsetX, ref offsetY) && elt != to); // If possible we stop as soon as we reach 'to'
Expand Down

0 comments on commit 17ca9d9

Please sign in to comment.