diff --git a/src/AtomUI.Controls/Tooltip/ToolTip.cs b/src/AtomUI.Controls/Tooltip/ToolTip.cs index eb00a5f79..c5bfd2c50 100644 --- a/src/AtomUI.Controls/Tooltip/ToolTip.cs +++ b/src/AtomUI.Controls/Tooltip/ToolTip.cs @@ -479,12 +479,10 @@ public partial class ToolTip : BorderedStyleControl, ITokenIdProvider _popup.VerticalOffset = offset.Y; var translatedSize = (_popup!.Host as WindowBase)!.ClientSize * scaling; - var flipInfo = CalculateFlipInfo(translatedSize, anchorRect, anchorAndGravity.Item1, anchorAndGravity.Item2, offset); var effectPlacement = placement; if (flipInfo.Item1 || flipInfo.Item2) { - var flipPlacement = FlipPlacementType(placement); var flipAnchorAndGravity = GetAnchorAndGravity(flipPlacement); var flipOffset = CalculateOffset(flipPlacement, control); @@ -497,7 +495,6 @@ public partial class ToolTip : BorderedStyleControl, ITokenIdProvider FlipPlacement = flipPlacement; _popup.HorizontalOffset = flipOffset.X; _popup.VerticalOffset = flipOffset.Y; - Console.WriteLine($"flip {CalculateOffset(flipPlacement, control)}"); } else { FlipPlacement = null; } @@ -559,24 +556,23 @@ public partial class ToolTip : BorderedStyleControl, ITokenIdProvider } if (GetIsShowArrow(control) && GetIsPointAtCenter(control)) { - Point anchorCenterPosition = default; var anchorSize = control.Bounds.Size; var centerX = anchorSize.Width / 2; var centerY = anchorSize.Height / 2; - if (direction == Direction.Top) { - anchorCenterPosition = new Point(centerX, 0); - } else if (direction == Direction.Bottom) { - anchorCenterPosition = new Point(centerX, anchorSize.Height); - } else if (direction == Direction.Left) { - anchorCenterPosition = new Point(0, centerY); - } else { - anchorCenterPosition = new Point(anchorSize.Width, centerY); + // 这里计算不需要全局坐标 + if (placementType == PlacementType.TopEdgeAlignedLeft || + placementType == PlacementType.BottomEdgeAlignedLeft) { + offsetX += centerX - ArrowPosition.Item1; + } else if (placementType == PlacementType.TopEdgeAlignedRight || + placementType == PlacementType.BottomEdgeAlignedRight) { + offsetX -= centerX - ArrowPosition.Item2; + } else if (placementType == PlacementType.RightEdgeAlignedTop || + placementType == PlacementType.LeftEdgeAlignedTop) { + offsetY += centerY - ArrowPosition.Item1; + } else if (placementType == PlacementType.RightEdgeAlignedBottom || + placementType == PlacementType.LeftEdgeAlignedBottom) { + offsetY -= centerY - ArrowPosition.Item2; } - - var globalAnchorCenterPos = control.PointToScreen(anchorCenterPosition); - anchorCenterPosition = new Point(globalAnchorCenterPos.X, globalAnchorCenterPos.Y); - - // Console.WriteLine($"{anchorCenterPosition}-{ArrowPoint}"); } return new Point(offsetX, offsetY); } @@ -662,7 +658,7 @@ public partial class ToolTip : BorderedStyleControl, ITokenIdProvider throw new InvalidOperationException("Target control is not in the same tree as the popup parent"); } - var anchorRect = new Rect(anchor.Bounds.Position, anchor.Bounds.Size); + var anchorRect = new Rect(default, anchor.Bounds.Size); return anchorRect.TransformToAABB(matrix.Value); } diff --git a/src/AtomUI.Controls/Tooltip/ToolTipStyle.cs b/src/AtomUI.Controls/Tooltip/ToolTipStyle.cs index a6653c57a..152cb5760 100644 --- a/src/AtomUI.Controls/Tooltip/ToolTipStyle.cs +++ b/src/AtomUI.Controls/Tooltip/ToolTipStyle.cs @@ -19,7 +19,7 @@ public partial class ToolTip : IControlCustomStyle private Rect _contentRect; private Rect _arrowRect; - internal Point? ArrowPoint { get; private set; } + internal (double, double) ArrowPosition { get; private set; } void IControlCustomStyle.SetupUi() { @@ -152,10 +152,10 @@ public partial class ToolTip : IControlCustomStyle var size = _arrowGeometry!.Bounds.Size; var targetWidth = 0d; var targetHeight = 0d; + var placement = GetEffectPlacement(); if (GetIsShowArrow(adornedControl)) { var minValue = Math.Min(size.Width, size.Height); var maxValue = Math.Max(size.Width, size.Height); - var placement = GetEffectPlacement(); if (placement == PlacementType.Left || placement == PlacementType.LeftEdgeAlignedTop || placement == PlacementType.LeftEdgeAlignedBottom) { @@ -178,7 +178,6 @@ public partial class ToolTip : IControlCustomStyle targetWidth = minValue; targetHeight = maxValue; - ArrowPoint = new Point(offsetX + targetWidth, offsetY + targetHeight / 2); } else if (placement == PlacementType.Top || placement == PlacementType.TopEdgeAlignedLeft || placement == PlacementType.TopEdgeAlignedRight) { @@ -192,7 +191,6 @@ public partial class ToolTip : IControlCustomStyle } else { offsetX = finalSize.Width - maxValue * 2; } - ArrowPoint = new Point(offsetX + targetWidth / 2, offsetY + targetHeight); } else if (placement == PlacementType.Right || placement == PlacementType.RightEdgeAlignedTop || placement == PlacementType.RightEdgeAlignedBottom) { @@ -214,7 +212,6 @@ public partial class ToolTip : IControlCustomStyle } } - ArrowPoint = new Point(offsetX, offsetY + targetHeight / 2); } else { if (placement == PlacementType.BottomEdgeAlignedLeft) { offsetX = maxValue; @@ -225,14 +222,20 @@ public partial class ToolTip : IControlCustomStyle } targetWidth = maxValue; targetHeight = minValue; - ArrowPoint = new Point(offsetX + targetWidth / 2, offsetY); } - - var globalPos = this.PointToScreen(ArrowPoint.Value); - ArrowPoint = new Point(globalPos.X, globalPos.Y); } - return new Rect(offsetX, offsetY, targetWidth, targetHeight); + var targetRect = new Rect(offsetX, offsetY, targetWidth, targetHeight); + var center = targetRect.Center; + // 计算中点 + var direction = GetDirection(placement); + if (direction == Direction.Left || direction == Direction.Right) { + ArrowPosition = (center.Y, finalSize.Height - center.Y); + } else if (direction == Direction.Top || direction == Direction.Bottom) { + ArrowPosition = (center.X, finalSize.Width - center.X); + } + + return targetRect; } private void BuildGeometry(Direction direction)