/// <summary> /// Calculates the size of the card layout container. /// </summary> /// <param name="obj">The container to lay out.</param> /// <param name="args">The parameters to use for layout.</param> /// <param name="direction">The direction which is being calculated.</param> /// <returns>The minimum and preferred box layout size.</returns> private static CardLayoutResults Calc(GameObject obj, PanelDirection direction) { var transform = obj.AddOrGet <RectTransform>(); int n = transform.childCount; var result = new CardLayoutResults(direction, n); var components = ListPool <Component, BoxLayoutGroup> .Allocate(); for (int i = 0; i < n; i++) { var child = transform.GetChild(i)?.gameObject; if (child != null) { bool active = child.activeInHierarchy; // Not only on active game objects components.Clear(); child.GetComponents(components); child.SetActive(true); var hc = PUIUtils.CalcSizes(child, direction, components); if (!hc.ignore) { result.Expand(hc); result.children.Add(hc); } child.SetActive(active); } } components.Recycle(); return(result); }
protected override void OnEnable() { base.OnEnable(); SetDirty(); horizontal = null; vertical = null; }
/// <summary> /// Lays out components in the card layout container. /// </summary> /// <param name="margin">The margin to allow around the components.</param> /// <param name="required">The calculated minimum and preferred sizes.</param> /// <param name="size">The total available size in this dimension.</param> private static void DoLayout(RectOffset margin, CardLayoutResults required, float size) { if (required == null) { throw new ArgumentNullException("required"); } var direction = required.direction; var components = ListPool <ILayoutController, BoxLayoutGroup> .Allocate(); // Compensate for margins if (direction == PanelDirection.Horizontal) { size -= margin.left + margin.right; } else { size -= margin.top + margin.bottom; } foreach (var child in required.children) { var obj = child.source; if (obj != null) { float compSize = PUIUtils.GetProperSize(child, size); // Place and size component var transform = obj.AddOrGet <RectTransform>(); if (direction == PanelDirection.Horizontal) { transform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, margin.left, compSize); } else { transform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, margin.top, compSize); } // Invoke SetLayout on dependents components.Clear(); obj.GetComponents(components); foreach (var component in components) { if (direction == PanelDirection.Horizontal) { component.SetLayoutHorizontal(); } else // if (direction == PanelDirection.Vertical) { component.SetLayoutVertical(); } } } } components.Recycle(); }
public void CalculateLayoutInputVertical() { var margin = Margin; float gap = (margin == null) ? 0.0f : margin.top + margin.bottom; vertical = Calc(gameObject, PanelDirection.Vertical); var vTotal = vertical.total; minHeight = vTotal.min + gap; preferredHeight = vTotal.preferred + gap; }
public void CalculateLayoutInputHorizontal() { var margin = Margin; float gap = (margin == null) ? 0.0f : margin.left + margin.right; horizontal = Calc(gameObject, PanelDirection.Horizontal); var hTotal = horizontal.total; minWidth = hTotal.min + gap; preferredWidth = hTotal.preferred + gap; }
internal CardLayoutGroup() { horizontal = null; layoutPriority = 1; vertical = null; }
protected override void OnDisable() { base.OnDisable(); horizontal = null; vertical = null; }