public double?GetOffset(ConnectedPosition position, string axis) { if (axis == "x") { // We don't do something like `position['offset' + axis]` in // order to avoid breking minifiers that rename properties. return(position.OffsetX ?? _offsetX); } return(position.OffsetY ?? _offsetY); }
/* * Adds new preferred positions. * @param positions List of positions options for this overlay. */ public FlexibleConnectedPositionStrategyBuilder WithPositions(List <ConnectedPosition> connectedPositions) { _preferredPositions = connectedPositions; var isOnPositions = connectedPositions.Contains(_lastPosition); if (!isOnPositions) { _lastPosition = null; } ValidatePositions(); return(this); }
/* Gets how well an overlay at the given point will fit within the viewport. */ public OverlayFit GetOverlayFit(Point point, ClientRect overlay, ClientRect viewport, ConnectedPosition position) { var x = point.X; var y = point.Y; var offsetX = GetOffset(position, "x"); var offsetY = GetOffset(position, "y"); // Account for the offsets since they could push the overlay out of the viewport. if (offsetX != null) { x += (double)offsetX; } if (offsetY != null) { y += (double)offsetY; } // How much the overlay would overflow at this position, on each side. var leftOverflow = 0 - x; var rightOverflow = (x + overlay.Width) - viewport.Width; var topOverflow = 0 - y; var bottomOverflow = (y + overlay.Height) - viewport.Height; // Visible parts of the element on each axis. var visibleWidth = this.SubtractOverflows(overlay.Width, new List <double> { leftOverflow, rightOverflow }); var visibleHeight = this.SubtractOverflows(overlay.Height, new List <double> { topOverflow, bottomOverflow }); var visibleArea = visibleWidth * visibleHeight; return(new OverlayFit() { VisibleArea = visibleArea, IsCompletelyWithinViewport = (overlay.Width * overlay.Height) == visibleArea, FitsInViewportVertically = visibleHeight == overlay.Height, FitsInViewportHorizontally = visibleWidth == overlay.Width, }); }