private void ConstraintWidthToFittingSizeIfNecessary(ref ComputeLayoutTuple layout) { if (width != null) { return; } if (layout.width < FittingWidth()) { layout.width = FittingWidth(); } }
private void ConstraintWidthToBoundsIfNecessary(ref ComputeLayoutTuple layout, UIWindow window) { var windowMaxX = window.Bounds.GetMaxX(); var maxX = layout.x + layout.width; if (maxX > windowMaxX) { var delta = maxX - windowMaxX; var newOrigin = layout.x - delta; if (newOrigin > 0) { layout.x = newOrigin; } else { layout.x = 0; layout.width += newOrigin; // newOrigin is negative, so this operation is a substraction } } }
private LayoutResult ComputeLayout() { var layout = new ComputeLayoutTuple(0, 0, 0, 0); var dir = Direction; var window = VisibleWindow(); if (window == null) { return(new LayoutResult(0, 0, 0, 0, 0, false, dir)); } if (anchorView != null) { var av = anchorView as UIBarButtonItemAnchorView; if (av != null) { var isRightBarButtonItem = anchorView.PlainView.Frame.GetMinX() > window.Frame.GetMidX(); if (isRightBarButtonItem) { nfloat w = width ?? FittingWidth(); var anchorViewWidth = anchorView.PlainView.Frame.Width; var x = -(w - anchorViewWidth); bottomOffset = new CGPoint(x, 0); } } } if (anchorView == null) { layout = ComputeLayoutBottomDisplay(window); Direction = Direction.Any; } else { switch (Direction) { case Direction.Any: layout = ComputeLayoutBottomDisplay(window); Direction = Direction.Bottom; if (layout.offscreenHeight > 0) { var topLayout = ComputeLayoutForTopDisplay(window); if (topLayout.offscreenHeight < layout.offscreenHeight) { layout = topLayout; Direction = Direction.Top; } } break; case Direction.Bottom: layout = ComputeLayoutBottomDisplay(window); Direction = Direction.Bottom; break; case Direction.Top: layout = ComputeLayoutForTopDisplay(window); Direction = Direction.Top; break; } } ConstraintWidthToFittingSizeIfNecessary(ref layout); ConstraintWidthToBoundsIfNecessary(ref layout, window); var visibleHeight = TableHeight - layout.offscreenHeight; var canBeDisplayed = visibleHeight >= minHeight; return(new LayoutResult(layout.x, layout.y, layout.width, layout.offscreenHeight, visibleHeight, canBeDisplayed, Direction)); }