public void SetFieldType(int index)
 {
     // initial value is for custom text
     if (index == 0)
     {
         if (!SetFieldTypeText(UiText.GetText(fieldType.gameObject)))
         {
             return;
         }
     }
     else if (index >= 1 && columnTypes[index - 1].uiField != null)
     {
         cHeader.columnSetting.data.columnUi = new Token(columnTypes[index - 1].uiField.name);
     }
     uds.RefreshRowAndColumnUi();
 }
Exemple #2
0
        public void RefreshHeaders()
        {
            if (headerRectangle == null)
            {
                return;
            }
            Vector2 cursor = Vector2.zero;
            // put old headers aside. they may be reused.
            List <GameObject> unusedHeaders = new List <GameObject>();

            for (int i = 0; i < headerRectangle.childCount; ++i)
            {
                GameObject header = headerRectangle.GetChild(i).gameObject;
                if (header != null)
                {
                    unusedHeaders.Add(header);
                }
            }
            while (headerRectangle.childCount > 0)
            {
                Transform t = headerRectangle.GetChild(headerRectangle.childCount - 1);
                t.SetParent(null, false);
            }
            errLog.ClearErrors();
            for (int i = 0; i < data.columnSettings.Count; ++i)
            {
                Udash.ColumnSetting colS   = data.columnSettings[i];
                GameObject          header = null;
                string headerObjName       = colS.data.headerUi.ResolveString(errLog, this);
                // check if the header we need is in the old header list
                object headerTextResult = colS.data.label.Resolve(errLog, data);
                if (errLog.HasError())
                {
                    popup.Set("err", null, errLog.GetErrorString()); return;
                }
                string headerTextString = headerTextResult?.ToString() ?? null;
                for (int h = 0; h < unusedHeaders.Count; ++h)
                {
                    GameObject hdr = unusedHeaders[h];
                    if (hdr.name.StartsWith(headerObjName) && UiText.GetText(hdr) == headerTextString)
                    {
                        header = hdr;
                        unusedHeaders.RemoveAt(h);
                        break;
                    }
                }
                if (header == null)
                {
                    GameObject headerObjectPrefab = uiPrototypes.GetElement(headerObjName);
                    header      = Instantiate(headerObjectPrefab);
                    header.name = header.name.SubstringBeforeFirst("(", headerObjName.Length) + "(" + colS.data.label + ")";
                    UiText.SetText(header, headerTextString);
                }
                ColumnHeader ch = header.GetComponent <ColumnHeader>();
                if (ch != null)
                {
                    ch.columnSetting = colS;
                }
                header.SetActive(true);
                header.transform.SetParent(headerRectangle, false);
                header.transform.SetSiblingIndex(i);
                RectTransform rect = header.GetComponent <RectTransform>();
                rect.anchoredPosition = cursor;
                float w = rect.sizeDelta.x;
                if (colS.data.widthOfColumn > 0)
                {
                    w = colS.data.widthOfColumn;
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, w);
                }
                else
                {
                    colS.data.widthOfColumn = w;                     // if the width isn't set, use the default width of the column header
                }
                cursor.x += w * rt.localScale.x;
            }
            contentAreaSize.x = cursor.x;
            for (int i = 0; i < unusedHeaders.Count; ++i)
            {
                GameObject header = unusedHeaders[i];
                Destroy(header);
            }
            unusedHeaders.Clear();
            contentRectangle.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, cursor.x);
            popup.Hide();
        }