Search Unity

GUI.Window dragging problems...

Discussion in 'Immediate Mode GUI (IMGUI)' started by JFo, Dec 9, 2007.

  1. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Hi!
    Just took a next step in my Unity enthusiasm and joined this nice community... :)

    I have been playing with the new GUI and found something I need to ask.

    The following code generates two Windows with one button each. These windows are normally draggable, BUT if you click one of the Buttons and by not releasing it, move cursor away from it, the windows are no longer draggable - even if they get focus. If I click the button again (with release) the situation will be normalized and dragging will work again.

    Code (csharp):
    1.  
    2. var windowRect0 : Rect = Rect (100, 100, 100, 50);
    3.  
    4. var windowRect1 : Rect = Rect (220, 100, 100, 50);
    5.  
    6.  
    7. function OnGUI () {
    8.     windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "My Window0");
    9.     windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "My Window1");
    10. }
    11.  
    12. function DoMyWindow (windowID : int) {
    13.     if ( GUI.Button (Rect (5, 20, 90, 20),"Click")) {
    14.         print ("Got a click in window " + windowID);
    15.     }
    16.     GUI.DragWindow ();
    17. }
    18.  
    I know this is one special case, but I have found similar behaviour in my more complex GUI tests ie.
    got the windows in state where they are no longer draggable.

    Any ideas what might be the reason and how to solve it?

    I found the GUI.FocusControl and GUI.SetNextControlName functions, but have no idea how to use
    them and if they are any help in this case!?

    Thank You in Advance,
    Juha
     
  2. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    Sounds like a bug. I'd bug report it with code that reproduces the problem.
     
  3. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    OK. Thanks for the advice. I'll send a bug report of that one.
    UPDATE: Got a message from Unity Support that this is going to be fixed...

    --

    Second part of my question was about the GUI.FocusControl and GUI.SetNextControlName functions. As the documentation of these are very limitted, I made a followin test:

    Code (csharp):
    1.  
    2. function OnGUI () {
    3.  
    4.     GUI.SetNextControlName("Win0");
    5.     GUI.Window (0, Rect (50, 50, 100, 80), DoMyWindow, "My Window0");
    6.    
    7.     GUI.SetNextControlName("Win1");
    8.     GUI.Window (1, Rect (150, 50, 100, 80), DoMyWindow, "My Window1");
    9. }
    10.  
    11. function DoMyWindow (windowID : int) {
    12.    if ( GUI.Button (Rect (5, 20, 90, 20),"Focus to Win0")) {
    13.  
    14.         GUI.FocusControl("Win0");
    15.    }
    16.    if ( GUI.Button (Rect (5, 50, 90, 20),"Focus to Win1")) {
    17.  
    18.         GUI.FocusControl("Win1");
    19.    }
    20. }
    21.  
    The expected (?) behavior to my understanding is following:
    "Focus to Win0" buttons should move focus to "My Window0" and "Focus to Win1" to "My Window1".

    However, only "My Window1" button "Focus to Win1" changes focus to "My Window0" and even that is wrong. So, either I don't understand the functions correctly or this is an another bug.

    Any ideas on that one? Or maybe some more detailed info how to use those focus related functions as the manual seems to be quite inadequate...

    TIA,
    Juha
     

    Attached Files:

  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    You've got the basics right...

    However, for it to truly work, the names need to be unique - that way you can also move focus between windows / different OnGUI scripts / etc.
     
  5. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    What do you mean by 'unique names'? Could you give me a hint how to choose valid names to replace "Win0" and "Win1" in my test script to make it work?

    Thanks,
    Juha
     
  6. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Answering to myself, it seems that in the current GUI system the "GUI.SetNextControlName" cannot be assigned to window elements.

    Code (csharp):
    1. function OnGUI () {
    2.  
    3.     GUI.SetNextControlName("Win0");    
    4.     GUI.Window (0, Rect (20, 10, 100, 100), DoMyWindow, "MyWindow0");
    5.     GUI.Button (Rect (25, 140, 90, 20),"Test0");
    6.  
    7.     GUI.SetNextControlName("Win1");    
    8.     GUI.Window (1, Rect (200, 10, 100, 100), DoMyWindow, "MyWindow1");
    9.     GUI.Button (Rect (205, 140, 90, 20),"Test1");
    10. }
    11.  
    12. function DoMyWindow (windowID : int) {
    13.    if ( GUI.Button (Rect (5, 50, 90, 20),"Focus to Win0")) {
    14.  
    15.         GUI.FocusControl("Win0");
    16.    }
    17.    if ( GUI.Button (Rect (5, 20, 90, 20),"Focus to Win1")) {
    18.  
    19.         GUI.FocusControl("Win1");
    20.    }
    21. }
    22.  
    When buttons in window elements are clicked, the focus will be moved to separate "Test" buttons below. You can see from the code that the control names are set before window elements and the "Test" buttons are defined right after the windows. For some reason, the naming will affect only those "Test" buttons and the window elements are ignored. This also explains the weird behaviour of the script in the previous post.

    If this is bug, I'll send detailed bug report. If not, I think that the manual should make it clear, that those focus related functions cannot be used with window elements itself.

    Although the new GUI have given me some puzzles, I somehow have started to like it.. :) Just have to think like OpenGL - not like conventional GUI toolboxes!

    BR,
    Juha
     

    Attached Files:

  7. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    I've just had a similar problem tonight.
    I have just 1 window, but if i click a control outside of the window, I can no longer drag it, until I click on a control (like a button or textfield) inside the window.
    Might be worth sending in a bug report.

    Cheers
    Shaun
     
  8. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Hi Shaun,
    I have sent the bug report about the dragging problem, so that part should be under investigation...

    BR,
    Juha