private void FixOriginXIfRightToLeft(GuiWidget parent) { if (parent.HAnchorIsSet(HAnchor.FitToChildren) && FlowDirection == UI.FlowDirection.RightToLeft) { 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 - encloseChildrenRect.Left, child.OriginRelativeParent.y); } } }
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); } } }
public void DoFitToChildrenVertical(GuiWidget widgetToAdjustBounds, ref bool sizeWasChanged) { if (widgetToAdjustBounds.VAnchorIsSet(VAnchor.FitToChildren)) { double heightToMatchParent = 0; if (widgetToAdjustBounds.Parent != null) { Vector2 newOriginRelParent; if (!GetOriginAndHeightForChild(widgetToAdjustBounds.Parent, widgetToAdjustBounds, 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 adjustBounds = widgetToAdjustBounds.LocalBounds; // get the bounds to enclose its childern RectangleDouble childrenEnclosingBounds = widgetToAdjustBounds.GetMinimumBoundsToEncloseChildren(true); // fix the v size to enclose the children adjustBounds.Bottom = childrenEnclosingBounds.Bottom; adjustBounds.Top = Math.Max(childrenEnclosingBounds.Bottom + heightToMatchParent, childrenEnclosingBounds.Top); if (widgetToAdjustBounds.LocalBounds != adjustBounds) { if (widgetToAdjustBounds.VAnchorIsSet(VAnchor.ParentBottomTop)) { if (widgetToAdjustBounds.LocalBounds.Height < adjustBounds.Height) { widgetToAdjustBounds.LocalBounds = adjustBounds; sizeWasChanged = true; } } else { // push the new size in widgetToAdjustBounds.LocalBounds = adjustBounds; sizeWasChanged = true; } } } }
public void DoFitToChildrenHorizontal(GuiWidget widgetToAdjust, ref bool sizeWasChanged) { if (widgetToAdjust.HAnchorIsSet(HAnchor.FitToChildren)) { double widthToMatchParent = 0; // let's check if the parent would like to make this widget bigger if (widgetToAdjust.Parent != null) { Vector2 newOriginRelParent; if (!GetOriginAndWidthForChild(widgetToAdjust.Parent, widgetToAdjust, out newOriginRelParent, out widthToMatchParent)) { // we don't need to adjust anything for the parent so make sure this is not applied below. widthToMatchParent = 0; } } // get the bounds RectangleDouble widgetToAdjustBounds = widgetToAdjust.LocalBounds; // get the bounds to enclose its childern RectangleDouble childrenEnclosingBounds = widgetToAdjust.GetMinimumBoundsToEncloseChildren(true); // fix the h size to enclose the children widgetToAdjustBounds.Left = childrenEnclosingBounds.Left; if (widgetToAdjust.Parent != null && widgetToAdjust.Parent.LayoutEngine != null) { if(widgetToAdjust.Parent.LayoutEngine as LayoutEngineFlow != null) { // The parent is a flow layout widget but it will only adjust our size if we are HAnchor leftright if (widgetToAdjust.HAnchorIsSet(HAnchor.ParentLeftRight)) { // We make the assumption that the parent has set the size correctly assuming flow layout and this can only be made bigger if fit needs to. widgetToAdjustBounds.Right = Math.Max(widgetToAdjustBounds.Right, childrenEnclosingBounds.Right); } else // we need to just do the fit to children { widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right); } } else if ((widgetToAdjust.Parent.LayoutEngine as LayoutEngineSimpleAlign) != null) { widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right); } else { throw new NotImplementedException(); } } else { widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right); } if (widgetToAdjust.LocalBounds != widgetToAdjustBounds) { if (widgetToAdjust.HAnchorIsSet(HAnchor.ParentLeftRight)) { if (widgetToAdjust.LocalBounds.Width < widgetToAdjustBounds.Width) { widgetToAdjust.LocalBounds = widgetToAdjustBounds; sizeWasChanged = true; } } else { // push the new size in widgetToAdjust.LocalBounds = widgetToAdjustBounds; sizeWasChanged = true; } } } }
public void DoFitToChildrenHorizontal(GuiWidget widgetToAdjust, ref bool sizeWasChanged) { if (widgetToAdjust.HAnchorIsSet(HAnchor.FitToChildren)) { double widthToMatchParent = 0; // let's check if the parent would like to make this widget bigger if (widgetToAdjust.Parent != null) { Vector2 newOriginRelParent; if (!GetOriginAndWidthForChild(widgetToAdjust.Parent, widgetToAdjust, out newOriginRelParent, out widthToMatchParent)) { // we don't need to adjust anything for the parent so make sure this is not applied below. widthToMatchParent = 0; } } // get the bounds RectangleDouble widgetToAdjustBounds = widgetToAdjust.LocalBounds; // get the bounds to enclose its childern RectangleDouble childrenEnclosingBounds = widgetToAdjust.GetMinimumBoundsToEncloseChildren(true); // fix the h size to enclose the children widgetToAdjustBounds.Left = childrenEnclosingBounds.Left; widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right); if (widgetToAdjust.LocalBounds != widgetToAdjustBounds) { // push the new size in widgetToAdjust.LocalBounds = widgetToAdjustBounds; sizeWasChanged = true; } } }