Search Unity

GUI sizing

Discussion in 'Immediate Mode GUI (IMGUI)' started by awilson, May 27, 2008.

  1. awilson

    awilson

    Joined:
    May 22, 2008
    Posts:
    13
    I have looked for this answer.

    Is there a good way to go about seating up gui's so that they can be sized correctly as the screen resolution sizes up or down?

    Fore example you have a button 64,64 and its location is 50,50 and that was set up for 1280 x 1024 and you want to give the user the option of sizing down to 1024 x 768 witch means that that the gui button needs to size down to 32,32 at the new location of 24,24 is there a good way to go about doing this?
     
  2. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    You could make a scale factor which you apply to all pixel values used in your GUI - offsets, positions, dimensions.

    For instance if your base level is 800x600, you could set it up like this:

    Code (csharp):
    1. void OnGUI()
    2. {
    3. float scaleX, scaleY;
    4.  
    5. scaleX = Screen.width / 800;
    6. scaleY = Screen.height / 600;
    7.  
    8. GUI.DrawTexture( new Rect( 100 * scaleX, 100 * scaleY, 200 * scaleX, 200 * scaleY ), myTexture );
    9. }
    Ofcourse for fonts you'd have to have fonts imported in various sizes and then toggle between them depending on the resolution.
     
  3. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Oo wait a sec. Thats silly. Theres already the GUI matrix for that.

    file:///Applications/Unity/Documentation/ScriptReference/GUI-matrix.html
     
  4. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
  5. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Oo nice. /me jots that down.
     
  6. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    I also highly recommend using GUILayout to flow content into windows, etc. That doesn't scale the whole GUI up or down, but maybe you'd rather let the GUI not occupy the entire screen on a larger screen, and GUILayout lets you adjust the window size and have the contents just work.
     
  7. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Btw, is there a way of finding out how much space is occupied by GUILayout? I'd like to use this for auto-resizing windows depending on the content displayed in those windows (i.e. when there's not much content, the window automatically becomes small, when there's much content, it automatically becomes bigger).

    At the moment, I'm using GUILayout for the layout, but also calculate the maximum width used and the sum of the height used myself... which is... not nice ;-)

    So is there something like "GUILayout.GetLastSize()", which I could then put into my window-rectangle to dynamically resize the window?

    Please forgive my thread-jacking, but at least this posting fits under the subject line ("GUI sizing") ;-)

    Sunny regards,
    Jashan
     
  8. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
  9. awilson

    awilson

    Joined:
    May 22, 2008
    Posts:
    13
    Thanks for the help.. is there any way I can see some code that would help me out.. been working on this for 5 day is all and I have a dead line for proof of concept to move forward so I am hoping that the community can help were the hard to fined / explanation has failed me.

    I have to wrap my head around it. just to give you some idea of how little I know I have yet to figure out how to set up so when you press a button you can change to the new gui layout / next page.

    Have you love the crazy dead lines of the unknown. :)

    Thanks to all that has helped me so far and to them that may help out in the future.