From ef0b6fd056f0ef1d667067af49e0ec8ebacf08d4 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 14 Oct 2021 22:55:00 -0400 Subject: [PATCH] fix(dragdrop): Fix support of transparent control in DragUI --- src/Uno.Foundation/Point.cs | 2 ++ src/Uno.UI/UI/Xaml/DragDrop/DragUI.cs | 6 ++--- src/Uno.UI/UI/Xaml/DragDrop/DragView.cs | 26 ++++++++++++++++--- src/Uno.UI/UI/Xaml/DragDrop/DragView.xaml | 14 ++++++++-- .../Imaging/RenderTargetBitmap.Android.cs | 23 +++++++++------- .../Media/Imaging/RenderTargetBitmap.iOS.cs | 4 +-- src/Uno.UI/UI/Xaml/UIElement.Pointers.cs | 23 +++++++++++----- 7 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/Uno.Foundation/Point.cs b/src/Uno.Foundation/Point.cs index eaf50e417f6b..cfef40dc1583 100644 --- a/src/Uno.Foundation/Point.cs +++ b/src/Uno.Foundation/Point.cs @@ -37,6 +37,8 @@ internal string ToDebugString() internal Point WithY(double y) => new Point(X, y); + internal Point GetOpposite() => new Point(-X, -Y); + public static bool operator ==(Point left, Point right) { return left.Equals(right); diff --git a/src/Uno.UI/UI/Xaml/DragDrop/DragUI.cs b/src/Uno.UI/UI/Xaml/DragDrop/DragUI.cs index 153603410fb8..d9a9bc0e5c82 100644 --- a/src/Uno.UI/UI/Xaml/DragDrop/DragUI.cs +++ b/src/Uno.UI/UI/Xaml/DragDrop/DragUI.cs @@ -10,12 +10,10 @@ public partial class DragUI { internal ImageSource? Content { get; set; } - internal Point? Anchor { get; private set; } + internal Point? Anchor { get; set; } public void SetContentFromBitmapImage(BitmapImage bitmapImage) - { - Content = bitmapImage; - } + => SetContentFromBitmapImage(bitmapImage, default); public void SetContentFromBitmapImage(BitmapImage bitmapImage, Point anchorPoint) { diff --git a/src/Uno.UI/UI/Xaml/DragDrop/DragView.cs b/src/Uno.UI/UI/Xaml/DragDrop/DragView.cs index 7cd8667cce2d..54a0caf2673f 100644 --- a/src/Uno.UI/UI/Xaml/DragDrop/DragView.cs +++ b/src/Uno.UI/UI/Xaml/DragDrop/DragView.cs @@ -69,6 +69,17 @@ public ImageSource? Content } #endregion + #region ContentAnchor + public static readonly DependencyProperty ContentAnchorProperty = DependencyProperty.Register( + "ContentAnchor", typeof(Point), typeof(DragView), new FrameworkPropertyMetadata(default(Point))); + + public Point ContentAnchor + { + get => (Point)GetValue(ContentAnchorProperty); + private set => SetValue(ContentAnchorProperty, value); + } + #endregion + #region ContentVisibility public static readonly DependencyProperty ContentVisibilityProperty = DependencyProperty.Register( "ContentVisibility", typeof(Visibility), typeof(DragView), new FrameworkPropertyMetadata(default(Visibility))); @@ -110,8 +121,8 @@ public void SetLocation(Point location) // TODO: Make sure to not move the element out of the bounds of the window _location = location; - _transform.X = location.X - (ActualWidth / 2); - _transform.Y = location.Y - 40; // The caption is above the pointer + _transform.X = location.X; + _transform.Y = location.Y; } public void Update(DataPackageOperation acceptedOperation, CoreDragUIOverride viewOverride) @@ -132,7 +143,16 @@ public void Update(DataPackageOperation acceptedOperation, CoreDragUIOverride vi GlyphVisibility = ToVisibility(viewOverride.IsGlyphVisible); Caption = caption!; CaptionVisibility = ToVisibility(viewOverride.IsCaptionVisible && !string.IsNullOrWhiteSpace(caption)); - Content = viewOverride.Content as ImageSource ?? _ui?.Content; + if (viewOverride.Content is ImageSource overridenContent) + { + Content = overridenContent; + ContentAnchor = viewOverride.ContentAnchor; + } + else + { + Content = _ui?.Content; + ContentAnchor = _ui?.Anchor ?? default; + } ContentVisibility = ToVisibility(viewOverride.IsContentVisible); TooltipVisibility = ToVisibility(viewOverride.IsGlyphVisible || viewOverride.IsCaptionVisible); Visibility = Visibility.Visible; diff --git a/src/Uno.UI/UI/Xaml/DragDrop/DragView.xaml b/src/Uno.UI/UI/Xaml/DragDrop/DragView.xaml index f6e7243b7cb5..cc1906c4ac77 100644 --- a/src/Uno.UI/UI/Xaml/DragDrop/DragView.xaml +++ b/src/Uno.UI/UI/Xaml/DragDrop/DragView.xaml @@ -14,7 +14,7 @@ xmlns:uBehaviors="using:Uno.UI.Behaviors" mc:Ignorable="d ios android wasm netstdref macos skia"> - +