Search Unity

Precise vertical alignment of GUI label

Discussion in 'Immediate Mode GUI (IMGUI)' started by Matt_RKLS, Jul 30, 2008.

  1. Matt_RKLS

    Matt_RKLS

    Joined:
    Sep 8, 2007
    Posts:
    94
    Hey all,

    Forgive my ignorance if this is covered somewhere that I have missed, but I just can't seem to get my GUI image to align correctly with the bottom of the application window. Here is the code I'm using:

    GUI.Label(Rect (0, 768 - image.height, image.width, image.height), image);

    The image is 61 px. wide x 64 px. tall.

    When running at 1024 x 768, the left side of the image aligns properly with the left side of the application window, but there is a small gap between the button and the bottom of the window. (see photo).

    Thanks for any help.

    Matt
     

    Attached Files:

  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Check the padding settings and make sure they are 0 (make a custom GUIStyle if necessary). Also you probably don't want to hard-code GUIs to particular resolutions.

    Code (csharp):
    1. var myStyle : GUIStyle; // Use 0,0,0,0 for padding
    2. var image : Texture2D;
    3.  
    4. function OnGUI () {
    5.    GUI.Label(Rect (0, Screen.height - image.height, image.width, image.height), image, myStyle);
    6. }
    --Eric
     
  3. Matt_RKLS

    Matt_RKLS

    Joined:
    Sep 8, 2007
    Posts:
    94
    Padding was the problem... thanks for the heads up. The hardcoded resolution value was just a leftover from my troubleshooting, [removing now] :)

    Thanks for the help.

    MJ