Exemple #1
0
        void HandleElementCallbackDelegate(Rect rect, int index, bool isActive, bool isFocused)
        {
            string value = currentEnum.entries[index];


            // Text fields do not like `null` values!
            if (value == null)
            {
                value          = "";
                ReBuildPreview = true;
            }


            Color _origColor = GUI.color;

            bool hasValidationResult = currentEnum.EntryValidations.ContainsKey(value);

            if (hasValidationResult)
            {
                EnumCreator.ValidationResult _validationResult = currentEnum.EntryValidations[value];

                if (!_validationResult.success)
                {
                    GUI.color = Color.red;
                }
            }

            // check if that index is validated
            string _newValue = EditorGUI.TextField(new Rect(rect.x, rect.y + 2, rect.width, rect.height - 4), new GUIContent("Entry " + index), value);


            GUI.color = _origColor;

            if ((index + 1) < currentEnum.entries.Count)
            {
                EditorGUI.DrawRect(new Rect(rect.x, rect.y + rect.height - 1, rect.width, 1), new Color(0.5f, 0.5f, 0.5f, 0.5f));
            }
            if (!string.Equals(_newValue, value))
            {
                currentEnum.entries[index] = _newValue;
                ReBuildPreview             = true;
            }
        }
Exemple #2
0
        private string DrawListItem(Rect position, string value)
        {
            // Text fields do not like `null` values!
            if (value == null)
            {
                value          = "";
                ReBuildPreview = true;
            }


            Color _origColor = GUI.color;

            bool hasValidationResult = currentEnum.EntryValidations.ContainsKey(value);

            if (hasValidationResult)
            {
                EnumCreator.ValidationResult _validationResult = currentEnum.EntryValidations[value];

                if (!_validationResult.success)
                {
                    GUI.color = Color.red;
                }
            }

            // check if that index is validated
            string _newValue = EditorGUI.TextField(position, value);

            GUI.color = _origColor;


            if (!string.Equals(_newValue, value))
            {
                ReBuildPreview = true;
            }
            return(_newValue);
        }