Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2.01k stars 414 forks source link

Broken nodes when using size computed with GUILayoutUtility.GetRect #24

Closed mitschoko closed 8 years ago

mitschoko commented 8 years ago

If i try to layout the node editor with an Rect returned by GUILayoutUtility.GetRect My nodes are broken ( the Header and the Knobs seem to be inPlace while the content is shifted. Non Broken Broken

Seneral commented 8 years ago

Hey mitschoko, this is because GUILayoutUtility.GetRect not only calculates a rect for you, but also reserves the space in the layout system. Usually, getRect is used to pass into normal GUI functions so that is ok, and that's also the reason why everything else in Node Editor is normal. Node Bodies however, use GUILayout.BeginArea, so you can use GUILayout funtions in the nodes. Somehow this interfers with the reserved space... I need to work out a solution for that, preferely so that I do not need to use GUILayout.BeginArea for node bodies :)

Seneral commented 8 years ago

Ok the above was just an assumption which prooved to be wrong after a test, fortunately. It was simply a bug when passing (0, 0, 1, 1), which GetRect returns when layouting. So changing the rect code to the following works:

Rect canvasRect = GUILayoutUtility.GetRect (600, 600);
if (Event.current.type != EventType.Layout)
    editorState.canvasRect = canvasRect;

Important is here the check for Layout event and that GetRect is still called when layouting to not throw errors:) Hope that fixes it for you;)