/// <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); }
/// <summary> /// Calculates the size of the box 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 BoxLayoutResults Calc(GameObject obj, BoxLayoutParams args, PanelDirection direction) { var transform = obj.AddOrGet <RectTransform>(); int n = transform.childCount; var result = new BoxLayoutResults(direction, n); var components = ListPool <Component, BoxLayoutGroup> .Allocate(); for (int i = 0; i < n; i++) { var child = transform.GetChild(i)?.gameObject; if (child != null && child.activeInHierarchy) { // Only on active game objects components.Clear(); child.GetComponents(components); var hc = PUIUtils.CalcSizes(child, direction, components); if (!hc.ignore) { if (args.Direction == direction) { result.Accum(hc, args.Spacing); } else { result.Expand(hc); } result.children.Add(hc); } } } components.Recycle(); return(result); }
public void CalculateLayoutInputHorizontal() { results = new GridLayoutResults(rows, columns, children); var elements = ListPool <Component, PGridLayoutGroup> .Allocate(); foreach (var component in results.Components) { // Cache size of children var obj = component.HorizontalSize.source; var margin = component.Margin; elements.Clear(); obj.GetComponents(elements); var sz = PUIUtils.CalcSizes(obj, PanelDirection.Horizontal, elements); if (!sz.ignore) { // Add borders int border = (margin == null) ? 0 : margin.left + margin.right; sz.min += border; sz.preferred += border; } component.HorizontalSize = sz; } elements.Recycle(); // Calculate columns sizes and our size results.CalcBaseWidths(); float width = results.MinWidth; if (Margin != null) { width += Margin.left + Margin.right; } minWidth = preferredWidth = width; flexibleWidth = (results.TotalFlexWidth > 0.0f) ? 1.0f : 0.0f; }
public override void CalculateLayoutInputVertical() { if (results != null && !locked) { var elements = ListPool <Component, PGridLayoutGroup> .Allocate(); foreach (var component in results.Components) { // Cache size of children var obj = component.VerticalSize.source; var margin = component.Margin; elements.Clear(); obj.GetComponents(elements); var sz = PUIUtils.CalcSizes(obj, PanelDirection.Vertical, elements); if (!sz.ignore) { // Add borders int border = (margin == null) ? 0 : margin.top + margin.bottom; sz.min += border; sz.preferred += border; } component.VerticalSize = sz; } elements.Recycle(); // Calculate row sizes and our size results.CalcBaseHeights(); float height = results.MinHeight; if (Margin != null) { height += Margin.bottom + Margin.top; } minHeight = preferredHeight = height; flexibleHeight = (results.TotalFlexHeight > 0.0f) ? 1.0f : 0.0f; } }
public override void CalculateLayoutInputVertical() { if (child != null && calcElements != null) { // Lay out children childVertical = PUIUtils.CalcSizes(child, PanelDirection.Vertical, calcElements); preferredHeight = childVertical.preferred; calcElements = null; } }
public override void CalculateLayoutInputHorizontal() { if (child != null) { calcElements = child.GetComponents <Component>(); // Lay out children childHorizontal = PUIUtils.CalcSizes(child, PanelDirection.Horizontal, calcElements); if (childHorizontal.ignore) { throw new InvalidOperationException("ScrollPane child ignores layout!"); } preferredWidth = childHorizontal.preferred; } }