예제 #1
0
        private void SetupTableContentPositionRecursively(VirtualGameObject child, TableLayoutRecord tableLayoutRecord)
        {
            // overwrite parent content width of TH and TD.
            if (child.tag == Tag.THEAD || child.tag == Tag.TBODY || child.tag == Tag.THEAD || child.tag == Tag.TR)
            {
                var width = tableLayoutRecord.TotalWidth();
                child.vRectTransform.vSizeDelta = new Vector2(width, child.vRectTransform.vSizeDelta.y);
            }

            /*
             *      change TH, TD content's x position and width.
             *      x position -> 0, 1st row's longest content len, 2nd row's longest content len,...
             *      width -> 1st row's longest content len, 2nd row's longest content len,...
             */
            if (child.tag == Tag.TH || child.tag == Tag.TD)
            {
                var offsetAndWidth = tableLayoutRecord.GetOffsetAndWidth();

                child.vRectTransform.vAnchoredPosition = new Vector2(offsetAndWidth.offset, child.vRectTransform.vAnchoredPosition.y);
                child.vRectTransform.vSizeDelta        = new Vector2(offsetAndWidth.width, child.vRectTransform.vSizeDelta.y);
            }

            foreach (var nestedChild in child.transform.GetChildlen())
            {
                child.SetupTableContentPositionRecursively(nestedChild, tableLayoutRecord);
            }
        }
예제 #2
0
        private void CollectTableContentRowCountRecursively(VirtualGameObject child, TableLayoutRecord tableLayoutRecord)
        {
            // count up table header count.
            if (child.tag == Tag.TH)
            {
                tableLayoutRecord.IncrementRow();
            }

            foreach (var nestedChild in child.transform.GetChildlen())
            {
                child.CollectTableContentRowCountRecursively(nestedChild, tableLayoutRecord);
            }
        }
예제 #3
0
        private void CollectTableContentRowMaxWidthsRecursively(VirtualGameObject child, TableLayoutRecord tableLayoutRecord)
        {
            var total = 0f;

            foreach (var nestedChild in child.transform.GetChildlen())
            {
                child.CollectTableContentRowMaxWidthsRecursively(nestedChild, tableLayoutRecord);
                if (child.tag == Tag.TH || child.tag == Tag.TD)
                {
                    var nestedChildContentWidth = nestedChild.vRectTransform.vSizeDelta.x;
                    total += nestedChildContentWidth;
                }
            }

            if (child.tag == Tag.TH || child.tag == Tag.TD)
            {
                tableLayoutRecord.UpdateMaxWidth(total);
            }
        }
예제 #4
0
        /**
         *      layout contents.
         *
         *      set position and size of content.
         */
        private HandlePoint Layout(VirtualGameObject parent, HandlePoint handlePoint, Tokenizer.OnLayoutDelegate onLayoutDel, Action <List <VirtualGameObject> > insert)
        {
            switch (this.tag)
            {
            case Tag.ROOT: {
                // do nothing.
                break;
            }

            default: {
                LayoutTagContent(handlePoint.nextLeftHandle, handlePoint.nextTopHandle, handlePoint.viewWidth, handlePoint.viewHeight, insert);
                break;
            }
            }

            // parent layout is done. will be resized by child, then padding.


            var childlen = this.transform.GetChildlen();

            if (0 < childlen.Count)
            {
                LayoutChildlen(childlen, handlePoint, onLayoutDel);

                /*
                 * set parent = this content's size to wrapping all childlen.
                 */
                var rightBottomPoint = Vector2.zero;

                // fit most large bottom-right point. largest point of width and y.
                foreach (var child in childlen)
                {
                    var paddedRightBottomPoint = child.PaddedRightBottomPoint();

                    if (rightBottomPoint.x < paddedRightBottomPoint.x)
                    {
                        rightBottomPoint.x = paddedRightBottomPoint.x;
                    }
                    if (rightBottomPoint.y < paddedRightBottomPoint.y)
                    {
                        rightBottomPoint.y = paddedRightBottomPoint.y;
                    }
                }

                // fit size to wrap all child contents.
                vRectTransform.vSizeDelta = rightBottomPoint;


                // calculate table's contents.
                if (this.tag == Tag.TABLE)
                {
                    /*
                     *      all contents size calculation inside this table is done.
                     *      count up row,
                     *      find longest content,
                     *      and adjust left point of contents.
                     */
                    var tableLayoutRecord = new TableLayoutRecord();

                    // countup rows.
                    foreach (var tableChild in this.transform.GetChildlen())
                    {
                        CollectTableContentRowCountRecursively(tableChild, tableLayoutRecord);
                    }

                    // find longest content.
                    foreach (var tableChild in this.transform.GetChildlen())
                    {
                        CollectTableContentRowMaxWidthsRecursively(tableChild, tableLayoutRecord);
                    }

                    // resize & reset position of this table contents by calculated record.
                    foreach (var tableChild in this.transform.GetChildlen())
                    {
                        SetupTableContentPositionRecursively(tableChild, tableLayoutRecord);
                    }
                }
            }

            /*
             *      set padding if need.
             *      default padding is 0.
             */
            onLayoutDel(this.tag, this.depth, this.padding, this.keyValueStore);

            /*
             *      adopt padding to this content.
             */
            {
                // translate anchor position of content.(child follows parent.)
                vRectTransform.vAnchoredPosition += padding.LeftTopPoint();

                handlePoint.nextLeftHandle += padding.PadWidth();
                handlePoint.nextTopHandle  += padding.PadHeight();
                // Debug.LogWarning("実験した方が良さそう");
            }
            // Debug.LogError("rectTransform.anchoredPosition:" + rectTransform.anchoredPosition);

            /*
             *      set next left-top point by parent tag kind.
             */
            switch (parent.tag)
            {
            default: {
                // 回り込みを実現する。んだけど、これはどちらかというと多数派で、デフォルトっぽい。
                // next content is planned to layout to the next of this content.
                handlePoint.nextLeftHandle = this.vRectTransform.vAnchoredPosition.x + this.vRectTransform.vSizeDelta.x + this.padding.PadWidth();                        // right edge with padding
                // Debug.LogError("handlePoint.nextLeftHandle:" + handlePoint.nextLeftHandle);
                break;
            }

            // Rootコンテンツにぶらさがっている項目は、全てCRLFがかかる。
            case Tag.ROOT: {
                // CRLF
                handlePoint.nextLeftHandle = 0;
                handlePoint.nextTopHandle += this.vRectTransform.vSizeDelta.y + this.padding.PadHeight();

                // Debug.LogError("親がRootなので、改行する。handlePoint.nextTopHandle:" + handlePoint.nextTopHandle + " of tag:" + tag + " rectTransform.anchoredPosition:" + this.rectTransform.anchoredPosition);
                break;
            }
            }

            return(handlePoint);
        }