public void UnPaintRow(DataGridViewRowUI selectedRow)
 {
     if (selectedRow != null)
     {
         selectedRow.cells.ForEach(c => c.GetComponent <Image>().color = color);
     }
 }
        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);
            }
        }
Пример #3
0
        public static GameObject CreateRow()
        {
            GameObject    row   = new GameObject("Row");
            RectTransform rowRT = row.AddComponent <RectTransform>();

            rowRT.sizeDelta = new Vector2(100f, 50f);
            DataGridViewRowUI     rowUI     = row.AddComponent <DataGridViewRowUI>();
            HorizontalLayoutGroup horLayout = row.AddComponent <HorizontalLayoutGroup>();

            horLayout.spacing = 1;
            horLayout.childForceExpandWidth = false;
            horLayout.childControlHeight    = false;
            horLayout.childControlWidth     = false;
            horLayout.childScaleHeight      = true;
            horLayout.childScaleWidth       = true;

            return(row);
        }
Пример #4
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!");
                }
            }
        }
 public void RemoveSelection()
 {
     UnPaintRow(selectedRow);
     selectedRow = null;
     rowSelectionChanged.Invoke(selectedRow);
 }
 void OnCellClicked(DataGridViewEventArgs args)
 {
     UnPaintRow(selectedRow);
     selectedRow = dataGrid.uiRows[args.row];
     PaintRow(selectedRow);
 }
 private void OnDisable()
 {
     selectedRow = null;
 }