Unity Community


Results 1 to 6 of 6

  1. Location
    Toronto, ON, Canada
    Posts
    90

    Actual Rect for GUILayout.Scrollview?

    Hello,

    I need the resulting Rect for a scrollview I have drawn with GUILayout.

    e.g.
    Code:  
    1. scroller = GUILayout.BeginScrollView( scroller );
    2.      // dynamic run-time data drawn
    3.      // in various Verticals/Horizontals
    4.      // possibly with FlexibleSpace
    5.  
    6. Rect scrollArea = ?

    Or even:
    Code:  
    1.   // various controls
    2.  
    3. Rect boxArea = ?

    I know you can use GUILayout.GetRect(...) to "reserve" the space for a single control like a Button--or more specifically for 1 piece of GUIContent--and then call the GUI equivalent with that Rect. But how do you find out how big your scrollview, or styled-BeginHorizontal() is? Even if I rewrite everything to GetRect() and GUI call, I still can't just union them all together because I'll need to clip it against the scroll view size, and I don't think you can get the size of the FlexibleSpace() either.

    In case it matters, I need the Rect so I can test dropping items with drag and drop against the screen-space mouse point coords. That works fine already everywhere else, but I at least need a Rect.

    Thanks in advance!

  2. Keyboard operator

    Location
    Copenhagen, Denmark
    Posts
    2,929
    As I understand it, you need the size of the clipping rect of the scroll view - not the internal area, right? If this is the case, you can receive the rect like this:
    Code:  
    1. scroller = GUILayout.BeginScrollView( scroller );
    2.      // dynamic run-time data drawn
    3.      // in various Verticals/Horizontals
    4.      // possibly with FlexibleSpace
    5.  
    Emil "AngryAnt" Johansen

    Game developer, AI specialist, Unity expert
    Freelancer, ex Unity Technologies

    AI in Unity, tips and tricks: http://angryant.com, http://twitter.com/angryant

    Coding bare-footed grants you extra CPU cycles!


    Want to play? http://angryant.com/freelance/
    Behave 2 is out! http://angryant.com/2013/12/23/Behave-2-2/
    Check out ReView!


  3. Location
    Toronto, ON, Canada
    Posts
    90
    I have never had any luck with that, and when I was writing this yesterday I noticed it is not in the docs, so I assumed it was broken and had been discretely removed.

    http://unity3d.com/support/documenta...utUtility.html

    I'll give it a try and let you know.

    Thanks!

    [Update: Yep, that seems to work perfectly. Now if I can just manage to not obsess over why it didn't work before, I can try to remember all the things I worked around when it didn't That will be so useful--thanks!]

  4. Keyboard operator

    Location
    Copenhagen, Denmark
    Posts
    2,929
    The fact that its missing from the docs is a bug and its being corrected for the next version of Unity.
    Emil "AngryAnt" Johansen

    Game developer, AI specialist, Unity expert
    Freelancer, ex Unity Technologies

    AI in Unity, tips and tricks: http://angryant.com, http://twitter.com/angryant

    Coding bare-footed grants you extra CPU cycles!


    Want to play? http://angryant.com/freelance/
    Behave 2 is out! http://angryant.com/2013/12/23/Behave-2-2/
    Check out ReView!


  5. Posts
    15
    And is there any function to get the INTERNAL area rect of scrollview?
    That is needed in my project to resize window dynamically when new text appears in it...


  6. Posts
    15
    actually, it is - to use BeginRender and EndRender in the child windows functions.

    Code:  
    1.     protected Rect lastRect;
    2.  
    3.     public void BeginRender()
    4.     {
    5.         scrollPos = GUILayout.BeginScrollView(scrollPos);
    6.         GUILayout.BeginVertical();
    7.     }
    8.  
    9.     public void EndRender()
    10.     {
    11.         if (Event.current.type == EventType.repaint)
    12.         {
    13.             Rect r = GUILayoutUtility.GetLastRect();
    14.             lastRect.x = lastRect.y = 0;
    15.             lastRect.width = r.width;
    16.             lastRect.height = r.yMin;
    17.         }
    18.         GUILayout.EndVertical();
    19.         GUILayout.EndScrollView();
    20.     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •