示例#1
0
        /// <summary>
        /// Lays out components in the box layout container against the layout axis.
        /// </summary>
        /// <param name="required">The calculated minimum and preferred sizes.</param>
        /// <param name="args">The parameters to use for layout.</param>
        /// <param name="status">The current status of layout.</param>
        private static void DoLayoutPerp(LayoutResults required, BoxLayoutParams args,
                                         LayoutStatus status)
        {
            var components = ListPool <ILayoutController, BoxLayoutGroup> .Allocate();

            var   direction = args.Direction;
            float size      = status.size;

            foreach (var child in required.children)
            {
                var obj = child.source;
                // Active objects only
                if (obj != null && obj.activeInHierarchy)
                {
                    float compSize = size;
                    if (child.flexible <= 0.0f)
                    {
                        // Does not expand to all
                        compSize = Math.Min(compSize, child.preferred);
                    }
                    float offset = (size > compSize) ? GetOffset(args, status.direction,
                                                                 size - compSize) : 0.0f;
                    // Place and size component
                    obj.AddOrGet <RectTransform>().SetInsetAndSizeFromParentEdge(status.edge,
                                                                                 offset + status.offset, compSize);
                    // Invoke SetLayout on dependents
                    components.Clear();
                    obj.GetComponents(components);
                    foreach (var component in components)
                    {
                        if (!PUIUtils.IgnoreLayout(component))
                        {
                            if (direction == PanelDirection.Horizontal)
                            {
                                component.SetLayoutVertical();
                            }
                            else                             // if (direction == PanelDirection.Vertical)
                            {
                                component.SetLayoutHorizontal();
                            }
                        }
                    }
                }
            }
            components.Recycle();
        }
示例#2
0
        /// <summary>
        /// Lays out components in the box layout container parallel to the layout axis.
        /// </summary>
        /// <param name="required">The calculated minimum and preferred sizes.</param>
        /// <param name="args">The parameters to use for layout.</param>
        /// <param name="status">The current status of layout.</param>
        private static void DoLayoutLinear(LayoutResults required, BoxLayoutParams args,
                                           LayoutStatus status)
        {
            var total      = required.total;
            var components = ListPool <ILayoutController, BoxLayoutGroup> .Allocate();

            var direction = args.Direction;
            // Determine flex size ratio
            float size = status.size, prefRatio = 0.0f, minSize = total.min, prefSize =
                total.preferred, excess = Math.Max(0.0f, size - prefSize), flexTotal = total.
                                                                                       flexible, offset = status.offset, spacing = args.Spacing;

            if (size > minSize && prefSize > minSize)
            {
                // Do not divide by 0
                prefRatio = Math.Min(1.0f, (size - minSize) / (prefSize - minSize));
            }
            if (excess > 0.0f && flexTotal == 0.0f)
            {
                // If no components can be expanded, offset all
                offset += GetOffset(args, status.direction, excess);
            }
            foreach (var child in required.children)
            {
                var obj = child.source;
                // Active objects only
                if (obj != null && obj.activeInHierarchy)
                {
                    float compSize = child.min;
                    if (prefRatio > 0.0f)
                    {
                        compSize += (child.preferred - child.min) * prefRatio;
                    }
                    if (excess > 0.0f && flexTotal > 0.0f)
                    {
                        compSize += excess * child.flexible / flexTotal;
                    }
                    // Place and size component
                    obj.AddOrGet <RectTransform>().SetInsetAndSizeFromParentEdge(status.edge,
                                                                                 offset, compSize);
                    offset += compSize + ((compSize > 0.0f) ? spacing : 0.0f);
                    // Invoke SetLayout on dependents
                    components.Clear();
                    obj.GetComponents(components);
                    foreach (var component in components)
                    {
                        if (!PUIUtils.IgnoreLayout(component))
                        {
                            if (direction == PanelDirection.Horizontal)
                            {
                                component.SetLayoutHorizontal();
                            }
                            else                             // if (direction == PanelDirection.Vertical)
                            {
                                component.SetLayoutVertical();
                            }
                        }
                    }
                }
            }
            components.Recycle();
        }