Exemplo n.º 1
0
    /// <summary>
    /// Reset the viewport back to the upper left origin of the scrollable area
    /// </summary>
    public void Reset()
    {
        try
        {
            SuspendLayout();

            if (autoLayout)
            {
                var savedScrollPosition = this.ScrollPosition;
                this.ScrollPosition = Vector2.zero;
                AutoArrange();
                ScrollPosition = savedScrollPosition;
            }
            else
            {
                scrollPadding = ScrollPadding.ConstrainPadding();

                var offset = (Vector3)calculateMinChildPosition();
                offset -= new Vector3(scrollPadding.left, scrollPadding.top);

                for (int i = 0; i < controls.Count; i++)
                {
                    controls[i].RelativePosition -= offset;
                }

                scrollPosition = Vector2.zero;
            }

            Invalidate();

            updateScrollbars();
        }
        finally
        {
            ResumeLayout();
        }
    }
Exemplo n.º 2
0
    private void AutoArrange()
    {
        SuspendLayout();
        try
        {
            scrollPadding = ScrollPadding.ConstrainPadding();
            flowPadding   = FlowPadding.ConstrainPadding();

            var x = (float)scrollPadding.left + (float)flowPadding.left - scrollPosition.x;
            var y = (float)scrollPadding.top + (float)flowPadding.top - scrollPosition.y;

            var maxWidth  = 0f;
            var maxHeight = 0f;

            for (int i = 0; i < controls.Count; i++)
            {
                var child = controls[i];

                if (!child.IsVisible || !child.enabled || !child.gameObject.activeSelf)
                {
                    continue;
                }

                if (child == this.horzScroll || child == this.vertScroll)
                {
                    continue;
                }

                if (this.wrapLayout)
                {
                    if (flowDirection == LayoutDirection.Horizontal)
                    {
                        if (x + child.Width >= size.x - scrollPadding.right)
                        {
                            x         = (float)scrollPadding.left + (float)flowPadding.left;
                            y        += maxHeight;
                            maxHeight = 0f;
                        }
                    }
                    else
                    {
                        if (y + child.Height + flowPadding.vertical >= size.y - scrollPadding.bottom)
                        {
                            y        = (float)scrollPadding.top + (float)flowPadding.top;
                            x       += maxWidth;
                            maxWidth = 0f;
                        }
                    }
                }

                var childPosition = new Vector2(x, y);
                child.RelativePosition = childPosition;

                var xofs = child.Width + flowPadding.horizontal;
                var yofs = child.Height + flowPadding.vertical;

                maxWidth  = Mathf.Max(xofs, maxWidth);
                maxHeight = Mathf.Max(yofs, maxHeight);

                if (flowDirection == LayoutDirection.Horizontal)
                {
                    x += xofs;
                }
                else
                {
                    y += yofs;
                }
            }

            updateScrollbars();
        }
        finally
        {
            ResumeLayout();
        }
    }