Siccity / xNode

Unity Node Editor: Lets you view and edit node graphs inside Unity
MIT License
3.27k stars 581 forks source link

TextField selection disappears #102

Open ManHunterGroms opened 5 years ago

ManHunterGroms commented 5 years ago

When you try to set the cursor in the text field, the cursor disappears. If you always press the left mouse button, it worked. I guess it is due: https://github.com/Siccity/xNode/issues/50 2019-01-21-18-51-53

cloudmoss commented 4 months ago

I needed to create a toolbar inside a graph editor, and ran into this issue since I needed some string property fields. For anyone stumbling upon this, and since no other solutions came up while I was searching, here's my workaround:

  1. Go to NodeEditorAction.cs, add a public boolean
    public bool disableControls { get; set; }
  2. Scroll down a bit to the Controls function, and add a return
    public void Controls() {
    if (disableControls) return;
    ....
  3. Now, inside your own graph editor, inside OnGUI, define your toolbar/whatever area using a rect. Mine looks like:
    var sidePanelRect = new Rect(0, 0, 300, window.position.height);
  4. Using the rect with GUILayout.BeginArea allows you to use EditorGUILayout and such as you normally would. Mine looks like:
    
    GUILayout.BeginArea(sidePanelRect);
    _sidePanelScrollPos = GUILayout.BeginScrollView(_sidePanelScrollPos);

// Some editor gui stuff here

GUILayout.EndScrollView(); GUILayout.EndArea();

5. Finally, at the end of OnGUI, simply add:
```cs
window.disableControls = sidePanelRect.Contains(Event.current.mousePosition);

This will stop xNode from listening to mouse events while the cursor is over your custom toolbar, therefore fixing the text input issue.