Beispiel #1
0
    public override void Create_Table(PUGameObject container, TableSpec spec)
    {
        float margin = DefaultFontSize();

        currentY -= paragraphSpacing();

        float savedY = currentY;

        PUGridLayoutGroup tableGroup = new PUGridLayoutGroup();

        tableGroup.SetFrame(padding.left + 2, currentY, container.size.Value.x, 100, 0, 1, "top,left");
        tableGroup.LoadIntoPUGameObject(container);

        // Fill out the group, then figure out the height / widths needed based upon the content
        float maxCellWidth  = 0;
        float maxCellHeight = 0;
        int   numberOfCols  = 0;
        int   numberOfRows  = 0;

        if (spec.Headers != null)
        {
            for (int i = 0; i < spec.Headers.Count; i++)
            {
                string          header    = spec.Headers [i];
                ColumnAlignment alignment = spec.Columns [i];

                TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left;
                if (alignment == ColumnAlignment.Right)
                {
                    tmAlignment = TMPro.TextAlignmentOptions.Right;
                }
                if (alignment == ColumnAlignment.Center)
                {
                    tmAlignment = TMPro.TextAlignmentOptions.Center;
                }

                PUTMPro text = AddTextWithOptions(tableGroup, header, DefaultFont(), textColor(), 1.0f, "Bold", tmAlignment);
                Vector2 size = text.rectTransform.sizeDelta + new Vector2(margin * 2.0f, margin);

                text.rectTransform.pivot     = Vector2.zero;
                text.rectTransform.anchorMax = Vector2.one;
                text.rectTransform.anchorMin = Vector2.zero;

                PutTextInBox(tableGroup, text, 2, new Color32(204, 204, 204, 255), new Color32(255, 255, 255, 255));
                text.SetStretchStretch(margin * 0.5f, margin, margin * 0.5f, margin);

                if (size.x > maxCellWidth)
                {
                    maxCellWidth = size.x;
                }
                if (size.y > maxCellHeight)
                {
                    maxCellHeight = size.y;
                }
            }
        }

        numberOfCols = spec.Rows[0].Count;
        numberOfRows = spec.Rows.Count;

        if (spec.Headers != null && spec.Headers.Count > 0)
        {
            numberOfRows++;
        }

        for (int i = 0; i < spec.Rows.Count; i++)
        {
            List <string> rows = spec.Rows[i];

            for (int j = 0; j < rows.Count; j++)
            {
                string row = rows[j];

                ColumnAlignment alignment = spec.Columns[j];

                TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left;
                if (alignment == ColumnAlignment.Right)
                {
                    tmAlignment = TMPro.TextAlignmentOptions.Right;
                }
                if (alignment == ColumnAlignment.Center)
                {
                    tmAlignment = TMPro.TextAlignmentOptions.Center;
                }


                PUTMPro text = AddTextWithOptions(tableGroup, row, DefaultFont(), textColor(), 1.0f, "Normal", tmAlignment);
                Vector2 size = text.rectTransform.sizeDelta + new Vector2(margin * 2.0f, margin);

                text.rectTransform.pivot     = Vector2.zero;
                text.rectTransform.anchorMax = Vector2.one;
                text.rectTransform.anchorMin = Vector2.zero;

                if (i % 2 != 0)
                {
                    PutTextInBox(tableGroup, text, 2, new Color32(204, 204, 204, 255), new Color32(248, 248, 248, 255));
                }
                else
                {
                    PutTextInBox(tableGroup, text, 2, new Color32(204, 204, 204, 255), new Color32(255, 255, 255, 255));
                }
                text.SetStretchStretch(margin * 0.5f, margin, margin * 0.5f, margin);

                if (size.x > maxCellWidth)
                {
                    maxCellWidth = size.x;
                }
                if (size.y > maxCellHeight)
                {
                    maxCellHeight = size.y;
                }
            }
        }

        tableGroup.layout.cellSize         = new Vector2(maxCellWidth, maxCellHeight);
        tableGroup.rectTransform.sizeDelta = new Vector2(maxCellWidth * numberOfCols, maxCellHeight * numberOfRows);
        currentY = savedY - tableGroup.rectTransform.sizeDelta.y;
    }
    public override void Create_Table(PUGameObject container, TableSpec spec)
    {
        float margin = DefaultFontSize();

        currentY -= paragraphSpacing();

        float savedY = currentY;

        PUGridLayoutGroup tableGroup = new PUGridLayoutGroup();
        tableGroup.SetFrame (padding.left+2, currentY, container.size.Value.x, 100, 0, 1, "top,left");
        tableGroup.LoadIntoPUGameObject (container);

        // Fill out the group, then figure out the height / widths needed based upon the content
        float maxCellWidth = 0;
        float maxCellHeight = 0;
        int numberOfCols = 0;
        int numberOfRows = 0;

        if (spec.Headers != null) {
            for (int i = 0; i < spec.Headers.Count; i++) {
                string header = spec.Headers [i];
                ColumnAlignment alignment = spec.Columns [i];

                TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left;
                if (alignment == ColumnAlignment.Right) {
                    tmAlignment = TMPro.TextAlignmentOptions.Right;
                }
                if (alignment == ColumnAlignment.Center) {
                    tmAlignment = TMPro.TextAlignmentOptions.Center;
                }

                PUTMPro text = AddTextWithOptions (tableGroup, header, DefaultFont (), textColor (), 1.0f, "Bold", tmAlignment);
                Vector2 size = text.rectTransform.sizeDelta + new Vector2 (margin * 2.0f, margin);

                text.rectTransform.pivot = Vector2.zero;
                text.rectTransform.anchorMax = Vector2.one;
                text.rectTransform.anchorMin = Vector2.zero;

                PutTextInBox (tableGroup, text, 2, new Color32 (204, 204, 204, 255), new Color32 (255, 255, 255, 255));
                text.SetStretchStretch (margin * 0.5f, margin, margin * 0.5f, margin);

                if (size.x > maxCellWidth) {
                    maxCellWidth = size.x;
                }
                if (size.y > maxCellHeight) {
                    maxCellHeight = size.y;
                }
            }
        }

        numberOfCols = spec.Rows[0].Count;
        numberOfRows = spec.Rows.Count;

        if (spec.Headers != null && spec.Headers.Count > 0) {
            numberOfRows++;
        }

        for(int i = 0; i < spec.Rows.Count; i++) {
            List<string> rows = spec.Rows[i];

            for(int j = 0; j < rows.Count; j++) {
                string row = rows[j];

                ColumnAlignment alignment = spec.Columns[j];

                TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left;
                if(alignment == ColumnAlignment.Right){
                    tmAlignment = TMPro.TextAlignmentOptions.Right;
                }
                if(alignment == ColumnAlignment.Center){
                    tmAlignment = TMPro.TextAlignmentOptions.Center;
                }

                PUTMPro text = AddTextWithOptions (tableGroup, row, DefaultFont(), textColor(), 1.0f, "Normal", tmAlignment);
                Vector2 size = text.rectTransform.sizeDelta + new Vector2(margin*2.0f,margin);

                text.rectTransform.pivot = Vector2.zero;
                text.rectTransform.anchorMax = Vector2.one;
                text.rectTransform.anchorMin = Vector2.zero;

                if(i % 2 != 0){
                    PutTextInBox (tableGroup, text, 2, new Color32 (204, 204, 204, 255), new Color32 (248, 248, 248, 255));
                }else{
                    PutTextInBox (tableGroup, text, 2, new Color32 (204, 204, 204, 255), new Color32 (255, 255, 255, 255));
                }
                text.SetStretchStretch (margin*0.5f, margin, margin*0.5f, margin);

                if(size.x > maxCellWidth){
                    maxCellWidth = size.x;
                }
                if(size.y > maxCellHeight){
                    maxCellHeight = size.y;
                }
            }
        }

        tableGroup.layout.cellSize = new Vector2 (maxCellWidth, maxCellHeight);
        tableGroup.rectTransform.sizeDelta = new Vector2 (maxCellWidth * numberOfCols, maxCellHeight * numberOfRows);
        currentY = savedY - tableGroup.rectTransform.sizeDelta.y;
    }