public void DoFitToChildrenVertical(GuiWidget widgetToAdjust, ref bool sizeWasChanged) { if (widgetToAdjust.VAnchorIsSet(VAnchor.FitToChildren)) { double heightToMatchParent = 0; if (widgetToAdjust.Parent != null) { Vector2 newOriginRelParent; if (!GetOriginAndHeightForChild(widgetToAdjust.Parent, widgetToAdjust, out newOriginRelParent, out heightToMatchParent)) { // we don't need to adjust anything for the parent so make sure this is not applied below. heightToMatchParent = 0; } } // get the bounds RectangleDouble parentBounds = widgetToAdjust.LocalBounds; // get the bounds to enclose its childern RectangleDouble childrenEnclosingBounds = widgetToAdjust.GetMinimumBoundsToEncloseChildren(true); // fix the v size to enclose the children parentBounds.Bottom = childrenEnclosingBounds.Bottom; parentBounds.Top = Math.Max(childrenEnclosingBounds.Bottom + heightToMatchParent, childrenEnclosingBounds.Top); if (widgetToAdjust.LocalBounds != parentBounds) { // push the new size in widgetToAdjust.LocalBounds = parentBounds; sizeWasChanged = true; } } }
private void FixOriginYIfTopToBottom(GuiWidget parent) { if (parent.VAnchorIsSet(VAnchor.FitToChildren) && FlowDirection == UI.FlowDirection.TopToBottom) { RectangleDouble encloseChildrenRect = parent.GetMinimumBoundsToEncloseChildren(); for (int childIndex = 0; childIndex < parent.Children.Count; childIndex++) { GuiWidget child = parent.Children[childIndex]; if (child.Visible == false) { continue; } child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.x, child.OriginRelativeParent.y - encloseChildrenRect.Bottom); } } }
protected override void ApplyVAnchorToChild(GuiWidget parent, GuiWidget child) { if (FlowDirection == UI.FlowDirection.LeftToRight || FlowDirection == UI.FlowDirection.RightToLeft) { base.ApplyVAnchorToChild(parent, child); } else { if (child.VAnchor == VAnchor.ParentBottomTop || child.VAnchorIsSet(VAnchor.FitToChildren)) { } else if (child.VAnchor != VAnchor.None) { throw new Exception("VAnchor for a top bottom flow widget needs to be none or ParentTopBottom."); } } }