Search Unity

When do the virtual methods in GUILayoutEntry get called?

Discussion in 'Immediate Mode GUI (IMGUI)' started by zwcloud, Jul 28, 2016.

  1. zwcloud

    zwcloud

    Joined:
    Mar 15, 2016
    Posts:
    377
    I have debugged codes in the OnGUI code in EditorWindow class and read the blog about unity3d's implementation of IMGUI by Richard Fine.

    Following shows two call of OnGUI. Just a glancing summary...

    1. First OnGUI:
    Code (CSharp):
    1.  
    2. Event.current.type == EventType.Layout; // True
    3. GUILayout.BeginHorizontal(); // Push a GUILayoutGroup to the current GUILayoutCache.
    4.     GUILayout.Button("buttonA"); // Add a GUILayoutEntry to the top level GUILayoutGroup's entry list.
    5.     GUILayout.Button("buttonB"); // Add a GUILayoutEntry to the top level GUILayoutGroup's entry list.
    6.     GUILayout.Button("buttonC"); // Add a GUILayoutEntry to the top level GUILayoutGroup's entry list.
    7. GUILayout.EndHorizontal(); // Pop GUILayoutGroup.
    8.  
    The rect of GUILayoutEntry objects changed between the two calls of OnGUI.

    2. Second OnGUI:
    Code (CSharp):
    1.  
    2. Event.current.type == EventType.Repaint; //True
    3. GUILayout.BeginHorizontal(); // Push a GUILayoutGroup to the current GUILayoutCache.
    4.     GUILayout.Button("buttonA"); // Read the rect of first GUILayoutEntry from the top level GUILayoutGroup's entry list.
    5.     GUILayout.Button("buttonB"); // Read the rect of second GUILayoutEntry from the top level GUILayoutGroup's entry list.
    6.     GUILayout.Button("buttonC"); // Read the rect of third GUILayoutEntry from the top level GUILayoutGroup's entry list.
    7. GUILayout.EndHorizontal(); // Pop GUILayoutGroup from the current GUILayoutCache.
    8.  
    GUILayoutEntry.rect only changes when GUILayoutEntry.SetHorizontal/SetVertical (and some other special method.) are called.
    I want to know when are those four virtual methods(SetHorizontal/SetVertical/CalcWidth/CalcHeight) of GUILayoutEntry called? Immediately after the call of OnGUI when the current event type is EventType.Layout? Are they called inside the internal implementation of Unity3D's C++ code?

    @superpig
     
  2. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Are you trying to make your own UI?
     
  3. zwcloud

    zwcloud

    Joined:
    Mar 15, 2016
    Posts:
    377
    Yes, I have alreay done much basic work now. But there is still much work to do, and this question is one of that.
     
  4. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    i cant say for sure... but you can look at some of the c# code, if you dig enough through the .net assemblies UnityEngine.dll i think, using ILSpy (google it).

    Sorry. Things like what you're asking might not be very well known by general developers. :p
     
  5. zwcloud

    zwcloud

    Joined:
    Mar 15, 2016
    Posts:
    377
    Sure. I have alreay looked into the codes with ILSpy. But find those virtual methods are called nowhere. Maybe they are called by the Unity editor's Window codes. I just want to make things more clear if someone knows about that.

    This is why I @superpig. :)
     
    IzzySoft likes this.
  6. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    All layout rects are calculated after the Layout Event OnGUI call has completed, but before the associated Repaint (or whatever other event) starts execution.

    If you want to dig into the IL, UnityEngine.GUIUtility.BeginGUI and UnityEngine.GUIUtility.EndGUI get called from native right before and after (respectively) the OnGUI call. EndGUI is where the calculation happens for the layout event.
     
    zwcloud and IzzySoft like this.
  7. zwcloud

    zwcloud

    Joined:
    Mar 15, 2016
    Posts:
    377
    Thank you for pointing that out.:D