#Field labels

1 messages · Page 1 of 1 (latest)

orchid light
#

Creating a thread to keep things cleaner.
I don't think I quite get what is going on, can you show me again and let me know exactly what you expect to see

fringe moon
#

There are two text fields

#

One for pattern and the other for input

#

The pattern text field uses
EditorGUI.PropertyField(position, property, label);

#

It is OK.

#

The second one is rendered using TextField.

#

As I mentiond, my problem is when I write

EditorGUI.PrefixLabel(position, label)

The text value in the first text field (pattern) is overlapped on the label!

#

rendered on top of the label (Regex)

#

When I replaced it with

  var inputRect =  position;

The overlapping problem is solved but the position/width is wrong

orchid light
#

Can ya share the full section of code?

fringe moon
#

yes

#
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.String)
        {
            position.height /= _isToggle ? 2f : 1f;
            position.width -= 30;
            EditorGUI.PropertyField(position, property, label);
            var toggleRect = new Rect(position.x + position.width + 10f-15*EditorGUI.indentLevel, position.y, 30, position.height);
            _isToggle = EditorGUI.Toggle(toggleRect, _isToggle);
            if (_isToggle)
            {
                HandleRegex(position, property, label);
            }
        }
    }

    private void HandleRegex(Rect position, SerializedProperty property, GUIContent label)
    {
        //var inputRect =  EditorGUI.PrefixLabel(position, label);
        var inputRect =  position;
        
        inputRect.x -= EditorGUI.indentLevel*15;
        inputRect.y += inputRect.height;
        inputRect.width -= 60;

        _input = EditorGUI.TextField(inputRect, _input, _style);

        var buttonRect = new Rect(inputRect.x + inputRect.width + 10, inputRect.y, 50, inputRect.height);
        GUI.backgroundColor = Color.yellow;
        if (GUI.Button(buttonRect, "Match"))
        {
            var pattern = property.stringValue;
            if (string.IsNullOrWhiteSpace(pattern) || string.IsNullOrWhiteSpace(_input))
            {
                _style = BackgroundStyle.Get(Color.red);
                return;
            }

            var matched = Regex.IsMatch(_input, pattern, RegexOptions.Singleline);
            _style = BackgroundStyle.Get(matched ? Color.green : Color.red);
        }

        GUI.backgroundColor = Color.white;
    }
#

Also, when the style changes, all of them change
I mean all fields using that attribute

#
 private GUIStyle _style = BackgroundStyle.Get(Color.white);
orchid light
fringe moon
fringe moon
#

Fields defined inside a drawer is shared?!

orchid light
fringe moon
#

WTH

orchid light
#

A single drawer is shared for all properties unless you disable it (there is an override for caching)

#

Honestly I would take a refactor pass over your layout code to clean it up a bit and streamline it.

#

It will probably help you fix the problem.

fringe moon
#

You are awesome

orchid light
#

Lol thanks, but why in this case?

fringe moon
#

I mean help me to solve my sh... problems

#

Do you think it is better to migrate to UIElements?

#

I have searched. Most features are supported or in the future will be supported

#

I did not get it

public override bool CanCacheInspectorGUI(SerializedProperty property)
    {
        return false;
    }

It could not solve my problem. As you said, the drawer is shared