Search Unity

How to center buttons and anchor to bottom

Discussion in 'Immediate Mode GUI (IMGUI)' started by steveg2357, Oct 16, 2014.

  1. steveg2357

    steveg2357

    Joined:
    Aug 21, 2014
    Posts:
    34
    I'd like to create a centered row of buttons and anchor it to the bottom of the screen (the following is a nominal example).

    Screen.jpg

    When I do the following in the OnGUI function in a UnityScript class that extends EditorWindow, it creates a row of buttons that are left aligned and are placed after the last GUI control.

    Code (JavaScript):
    1. EditorGUILayout.BeginHorizontal();
    2. var myButton1 = GUILayout.Button("Done", GUILayout.ExpandWidth(false));
    3. var myButton2 = GUILayout.Button("Cancel", GUILayout.ExpandWidth(false));
    4. EditorGUILayout.EndHorizontal();
    Is there a way to modify or use something similar to the above without specifying one or more rectangles with coordinates relative to the screen size?
     
  2. Avalion

    Avalion

    Joined:
    May 2, 2012
    Posts:
    34
    You can use GUILayout.FlexibleSpace() to align elements where you want on GUI.

    Avalion