Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GUI.tooltip behavior specifics / details?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Joe ByDesign, Mar 22, 2008.

  1. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    I've a moderately complex GUI (using GUILayout) and I'm seeing strangeness trying to get a GUI.tooltip label working consistently.

    A very basic representation in pseudo code is:

    Code (csharp):
    1. Vertical
    2.   Horizontal
    3.     GroupOfButtonsWithToolTips1
    4.     GroupOfButtonsWithToolTips2
    5.   EndHorizontal
    6.  
    7.  Label (GUI.tooltip)
    8.  
    9.   Horizontal
    10.     GroupOfButtonsWithToolTips3
    11.     GroupOfButtonsWithToolTips4
    12.   EndHorizontal
    13.  
    14. EndVertical
    15.  
    The problem is that I'm seeing 1 of 2 outcomes, neither of which is desirable:

    1. The Label only shows tooltips from the top 2 Groups of Buttons, but the Label is not centered (as shown).
    2. Adding code to center the Label (by bracing the Label in a new Horizontal FlexibleSpaces), I see no tooltips at all from any group.
    I've tried deferring the tooltip to a string for the Label and setting the string value with GUI.tooltip following various declarations (ex: after creating each group of buttons), but nothing I do seems to result in anything other than 1 of the above 2 outcomes.

    Soooo... what are the specifics that govern the GUI.tooltip value being updated or not? Are there limits to the number of group levels before it is no longer updated?
     
  2. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Is the code all within the same OnGUI function?
     
  3. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    The 'group of buttons' part of the code uses a coroutine outside of OnGUI. Is this not allowed?

    I will try to rework it be inline with OnGUI, to see if that has an affect; but it sure makes for painful and redundant GUI code. :(
     
  4. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    It sounds very probable that your messing with a coroutine from within OnGUI i what is causing your problem. OnGUI needs to be serialised by unity for optimisation.

    For more info on this I recommend watching the unity 2.0 GUI presentation located here: http://unity3d.com/support/resources/unite-presentations/
     
  5. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Thanks for the reminder Emil. I recall the change to make GUI calls only work from OnGUI, but thought since I wasn't seeing the typical "put GUI calls inside OnGUI dummy!" error messages in the above case (a bug?) I presumed the problem was somewhere else!

    To make things even more oh so interesting, I moved all the subroutine methods inline to OnGUI to verify, and saw no change in behavior to either outcome :(

    I'm stumped!

    * Update: If I move the tooltip Label call to exist beneath / outside of the EndVertical call (see code block in the original post), then outcome 1 disappears (tooltip appears for all button groups). However, outcome 2 still exists...

    The plot thickens!
     
  6. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    I am not sure about all the things, but there here's a few pointers:

    The tooltip label should be at the end of your GUI code. The tooltip gets picked up during the repaint event, so it will not pick up anything coming in _after_ displaying it.

    How about just using GUI.Label instead of GUILayout? Once GUI gets over a certain complexity GUILayout tends to be more work than it's worth.
     
    Sawukoa likes this.
  7. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    I'll give it a go; the main issue is that the GUI elements are all in a window, so I'll have to do a little crunching to make sure that the GUI.Label rect gets updated appropriately.

    Considering the tooltip label needs to be at the end to function properly, it sounds like using GUI.Label is pretty much required (if you want the label anywhere but at the end)... might be worth updating the documentation with these specifics.
     
  8. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    If you're inside a window (0,0) is top-left of the window.

    The other way of doing this is getting a rect back from GUILayout.

    pseudocode:
    Code (csharp):
    1.  
    2. Horizontal {
    3.   Image
    4.   Image
    5. }
    6.  
    7. Rect r = GUILayoutUtility.GetRect (200,20);
    8.  
    9. Horizontal {
    10.   Image
    11.   Image
    12. }
    13.  
    14. GUI.Label (r, GUI.tooltip);
    15.  
     
  9. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    That did the trick! Tooltip clarified!

    Thanks Nicholas!