private static Point Gravitate(Point anchorPoint, Size size, PopupGravity gravity)
        {
            double x, y;

            if ((gravity & PopupGravity.Left) != 0)
            {
                x = -size.Width;
            }
            else if ((gravity & PopupGravity.Right) != 0)
            {
                x = 0;
            }
            else
            {
                x = -size.Width / 2;
            }

            if ((gravity & PopupGravity.Top) != 0)
            {
                y = -size.Height;
            }
            else if ((gravity & PopupGravity.Bottom) != 0)
            {
                y = 0;
            }
            else
            {
                y = -size.Height / 2;
            }
            return(anchorPoint + new Point(x, y));
        }
Esempio n. 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);
            }
Esempio n. 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();
            }
        }