예제 #1
0
    public void PutTextInBox(PUGameObject container, PUTMPro text, float margin, Color outlineColor, Color backgroundColor)
    {
        PUColor outlineColorGO = new PUColor();

        outlineColorGO.color = outlineColor;
        outlineColorGO.SetFrame(text.rectTransform.anchoredPosition.x, text.rectTransform.anchoredPosition.y, text.rectTransform.sizeDelta.x + margin * 2.0f, text.rectTransform.sizeDelta.y + margin * 2.0f, 0, 1, "top,left");
        outlineColorGO.LoadIntoPUGameObject(container);

        PUColor backgroundColorGO = new PUColor();

        backgroundColorGO.color = backgroundColor;
        backgroundColorGO.SetFrame(0, 0, 0, 0, 0, 0, "stretch,stretch");
        backgroundColorGO.LoadIntoPUGameObject(outlineColorGO);
        backgroundColorGO.SetStretchStretch(1, 1, 1, 1);

        text.rectTransform.SetParent(outlineColorGO.rectTransform, false);
        text.rectTransform.pivot     = Vector2.zero;
        text.rectTransform.anchorMax = Vector2.one;
        text.rectTransform.anchorMin = Vector2.zero;
        text.SetStretchStretch(margin, margin, margin, margin);
    }
예제 #2
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 void PutTextInBox(PUGameObject container, PUTMPro text, float margin, Color outlineColor, Color backgroundColor)
    {
        PUColor outlineColorGO = new PUColor ();
        outlineColorGO.color = outlineColor;
        outlineColorGO.SetFrame (text.rectTransform.anchoredPosition.x,text.rectTransform.anchoredPosition.y,text.rectTransform.sizeDelta.x + margin * 2.0f,text.rectTransform.sizeDelta.y + margin * 2.0f,0,1,"top,left");
        outlineColorGO.LoadIntoPUGameObject (container);

        PUColor backgroundColorGO = new PUColor ();
        backgroundColorGO.color = backgroundColor;
        backgroundColorGO.SetFrame (0, 0, 0, 0, 0, 0, "stretch,stretch");
        backgroundColorGO.LoadIntoPUGameObject (outlineColorGO);
        backgroundColorGO.SetStretchStretch (1, 1, 1, 1);

        text.rectTransform.SetParent (outlineColorGO.rectTransform, false);
        text.rectTransform.pivot = Vector2.zero;
        text.rectTransform.anchorMax = Vector2.one;
        text.rectTransform.anchorMin = Vector2.zero;
        text.SetStretchStretch (margin, margin, margin, margin);
    }