Exemplo n.º 1
0
        public static GameObject CreateCell()
        {
            GameObject    cellObject = new GameObject("Cell");
            Button        cellButton = cellObject.AddComponent <Button>();
            RectTransform cellRT     = cellObject.AddComponent <RectTransform>();

            cellRT.sizeDelta = new Vector2(100f, 50f);
            cellObject.AddComponent <Image>();

            DataGridViewCellUI cell       = cellObject.AddComponent <DataGridViewCellUI>();
            GameObject         textObject = new GameObject("Text");

            Text text = textObject.AddComponent <Text>();

            text.font      = Resources.Load <Font>("Fonts/PT Astra Sans/PT-Astra-Sans_Regular");
            text.color     = Color.white;
            text.alignment = TextAnchor.MiddleCenter;
            text.text      = "HeaderElement";

            RectTransform textRT = textObject.GetComponent <RectTransform>();

            textRT.SetParent(cellRT);
            textRT.anchorMin = Vector2.zero;
            textRT.anchorMax = Vector2.one;
            textRT.offsetMin = Vector2.zero;
            textRT.offsetMax = Vector2.zero;

            cell.textComponent   = text;
            cell.buttonComponent = cellButton;

            return(cellObject);
        }
        public void PaintRow(DataGridViewRowUI selectedRow)
        {
            DataGridViewCellUI cellUI = selectedRow.cells[0];

            if (cellUI != null)
            {
                Image cellImage = cellUI.GetComponent <Image>();
                color = cellImage.color;

                selectedRow.cells.ForEach(c => c.GetComponent <Image>().color = selectedColor);
                rowSelectionChanged.Invoke(selectedRow);
            }
        }
Exemplo n.º 3
0
        public void OnChange()
        {
            if (rows.Count > 0)
            {
                if (rows?[0].cells.Count == columns?.Count)
                {
                    if (uiRows.Count > 0)
                    {
                        ClearRows();
                    }

                    for (int i = 0; i < rows.Count; i++)
                    {
                        DataGridViewRow   row       = rows[i];
                        GameObject        rowObject = DataGridViewRowUI.CreateRow();
                        DataGridViewRowUI rowUI     = rowObject.GetComponent <DataGridViewRowUI>();

                        for (int j = 0; j < row.cells.Count; j++)
                        {
                            GameObject cell = DataGridViewCellUI.CreateCell();

                            Image cellImage = cell.GetComponent <Image>();
                            if (colorRows)
                            {
                                cellImage       = cell.GetComponent <Image>();
                                cellImage.color = i == 0 || i % 2 == 0 ? even : odd;
                            }
                            else
                            {
                                cellImage.color = even;
                            }

                            RectTransform cellRT   = cell.GetComponent <RectTransform>();
                            RectTransform headerRT = columns[j].GetComponent <RectTransform>();
                            cellRT.sizeDelta = new Vector2(headerRT.sizeDelta.x, cellRT.sizeDelta.y);

                            cell.transform.SetParent(rowUI.transform);
                            DataGridViewCellUI cellUI = cell.GetComponent <DataGridViewCellUI>();

                            if (tableFont)
                            {
                                cellUI.textComponent.font = tableFont;
                            }

                            cellUI.textComponent.color = cellTextColor;
                            cellUI.textComponent.text  = row.cells[j].value;

                            Button cellButton          = cell.GetComponent <Button>();
                            DataGridViewEventArgs args = new DataGridViewEventArgs(i, j);
                            cellButton.onClick.AddListener(OnClick);

                            rowUI.cells.Add(cellUI);

                            void OnClick()
                            {
                                cellClicked.Invoke(args);
                                cellDoubleClicked.Invoke(args);
                            }
                        }


                        uiRows.Add(rowUI);
                    }

                    uiRows.ForEach(r =>
                    {
                        r.transform.SetParent(rowsComponent.transform);
                        RectTransform rowRT      = r.GetComponent <RectTransform>();
                        rowRT.anchoredPosition3D = Vector3.zero;
                        rowRT.localScale         = Vector3.one;
                        rowRT.localRotation      = Quaternion.Euler(Vector3.zero);
                    });
                }
                else
                {
                    throw new System.Exception("Cells count don't match with header!");
                }
            }
        }