private static Point GetAnchorPoint(Rect anchorRect, PopupAnchor edge)
        {
            double x, y;

            if ((edge & PopupAnchor.Left) != 0)
            {
                x = anchorRect.X;
            }
            else if ((edge & PopupAnchor.Right) != 0)
            {
                x = anchorRect.Right;
            }
            else
            {
                x = anchorRect.X + anchorRect.Width / 2;
            }

            if ((edge & PopupAnchor.Top) != 0)
            {
                y = anchorRect.Y;
            }
            else if ((edge & PopupAnchor.Bottom) != 0)
            {
                y = anchorRect.Bottom;
            }
            else
            {
                y = anchorRect.Y + anchorRect.Height / 2;
            }
            return(new Point(x, y));
        }
Example #2
0
 public void ConfigurePosition(IVisual target, PlacementMode placement, Point offset,
                               PopupAnchor anchor = PopupAnchor.None, PopupGravity gravity = PopupGravity.None,
                               PopupPositionerConstraintAdjustment constraintAdjustment = PopupPositionerConstraintAdjustment.All,
                               Rect?rect = null)
 {
     _positionerParameters.ConfigurePosition((TopLevel)_overlayLayer.GetVisualRoot(), target, placement, offset, anchor,
                                             gravity, constraintAdjustment, rect);
     UpdatePosition();
 }
        private Rect Calculate(Size translatedSize,
                               Rect anchorRect, PopupAnchor anchor, PopupGravity gravity,
                               PopupPositionerConstraintAdjustment constraintAdjustment, Point offset)
        {
            var parentGeometry = _popup.ParentClientAreaScreenGeometry;

            anchorRect = anchorRect.Translate(parentGeometry.TopLeft);

            Rect GetBounds()
            {
                var screens = _popup.Screens;

                var targetScreen = screens.FirstOrDefault(s => s.Bounds.Contains(anchorRect.TopLeft))
                                   ?? screens.FirstOrDefault(s => s.Bounds.Intersects(anchorRect))
                                   ?? screens.FirstOrDefault(s => s.Bounds.Contains(parentGeometry.TopLeft))
                                   ?? screens.FirstOrDefault(s => s.Bounds.Intersects(parentGeometry))
                                   ?? screens.FirstOrDefault();

                if (targetScreen != null && targetScreen.WorkingArea.IsEmpty)
                {
                    return(targetScreen.Bounds);
                }

                return(targetScreen?.WorkingArea
                       ?? new Rect(0, 0, double.MaxValue, double.MaxValue));
            }

            var bounds = GetBounds();

            bool FitsInBounds(Rect rc, PopupAnchor edge = PopupAnchor.AllMask)
            {
                if ((edge & PopupAnchor.Left) != 0 &&
                    rc.X < bounds.X)
                {
                    return(false);
                }

                if ((edge & PopupAnchor.Top) != 0 &&
                    rc.Y < bounds.Y)
                {
                    return(false);
                }

                if ((edge & PopupAnchor.Right) != 0 &&
                    rc.Right > bounds.Right)
                {
                    return(false);
                }

                if ((edge & PopupAnchor.Bottom) != 0 &&
                    rc.Bottom > bounds.Bottom)
                {
                    return(false);
                }

                return(true);
            }
Example #4
0
        public void ConfigurePosition(IVisual target, PlacementMode placement, Point offset,
                                      PopupAnchor anchor   = PopupAnchor.None,
                                      PopupGravity gravity = PopupGravity.None,
                                      PopupPositionerConstraintAdjustment constraintAdjustment = PopupPositionerConstraintAdjustment.All,
                                      Rect?rect = null)
        {
            _positionerParameters.ConfigurePosition(_parent, target,
                                                    placement, offset, anchor, gravity, constraintAdjustment, rect);

            if (_positionerParameters.Size != default)
            {
                UpdatePosition();
            }
        }
Example #5
0
        private Point GetPopupPoint(Rectangle r, out PopupAnchor anchor)
        {
            Point pt;

            switch (_Panel.ColumnHeader.FilterImageAlignment)
            {
                case Alignment.TopRight:
                case Alignment.MiddleRight:
                case Alignment.BottomRight:
                    anchor = PopupAnchor.Right;
                    pt = new Point(r.Right + 2, r.Bottom + 4);
                    break;

                default:
                    anchor = PopupAnchor.Left;
                    pt = new Point(r.X - 2, r.Bottom + 4);
                    break;
            }

            pt = _Panel.SuperGrid.PointToScreen(pt);

            return (pt);
        }