# Window

> Make a popup window that layouts its contents automatically.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.IMGUIModule

## Window(int, Rect, WindowFunction, string, GUILayoutOption\[])

Make a popup window that layouts its contents automatically.

```csharp
public static Rect Window(int id, Rect screenRect, GUI.WindowFunction func, string text, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique ID to use for each window. This is the ID you'll use to interface to it.**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the window. The layouting system will attempt to fit the window inside it - if that cannot be done, it will adjust the rectangle to fit.**** (\[WindowFunction]\(/engine/6000.6/script-reference/unityengine/gui/windowfunction)): The function that creates the GUI `inside` the window. This function must take one parameter - the `id` of the window it's currently making GUI for.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to display as a title for the window.**** (\[GUILayoutOption\[]]\(/engine/6000.6/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style` or the `screenRect` you pass in.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.6/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.6/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.6/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.6/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.6/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.6/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.6/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.6/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                                                                               |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| [Rect](/engine/6000.6/script-reference/unityengine/rect.md) | The rectangle the window is at. This can be in a different position and have a different size than the one you passed in. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:

![GUILayoutWindow (Window)](/api/media?file=/engine/6000.6/media/images/GUILayoutWindow.png)

*Window in the Game View.*

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button will size to fit the window
        if (GUILayout.Button("Hello World"))
        {
            print("Got a click");
        }
    }
}
```

The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Here we instruct the layout system to
        // make the window 100 pixels wide no matter what.
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100));
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button is too large to fit the window
        // Normally, the window would have been expanded to fit the button, but due to
        // the GUILayout.Width call above the window will only ever be 100 pixels wide
        if (GUILayout.Button("Please click me a lot"))
        {
            print("Got a click");
        }
    }
}
```

## Window(int, Rect, WindowFunction, Texture, GUILayoutOption\[])

Make a popup window that layouts its contents automatically.

```csharp
public static Rect Window(int id, Rect screenRect, GUI.WindowFunction func, Texture image, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique ID to use for each window. This is the ID you'll use to interface to it.**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the window. The layouting system will attempt to fit the window inside it - if that cannot be done, it will adjust the rectangle to fit.**** (\[WindowFunction]\(/engine/6000.6/script-reference/unityengine/gui/windowfunction)): The function that creates the GUI `inside` the window. This function must take one parameter - the `id` of the window it's currently making GUI for.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display an image in the titlebar.**** (\[GUILayoutOption\[]]\(/engine/6000.6/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style` or the `screenRect` you pass in.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.6/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.6/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.6/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.6/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.6/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.6/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.6/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.6/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                                                                               |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| [Rect](/engine/6000.6/script-reference/unityengine/rect.md) | The rectangle the window is at. This can be in a different position and have a different size than the one you passed in. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:

![GUILayoutWindow (Window)](/api/media?file=/engine/6000.6/media/images/GUILayoutWindow.png)

*Window in the Game View.*

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button will size to fit the window
        if (GUILayout.Button("Hello World"))
        {
            print("Got a click");
        }
    }
}
```

The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Here we instruct the layout system to
        // make the window 100 pixels wide no matter what.
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100));
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button is too large to fit the window
        // Normally, the window would have been expanded to fit the button, but due to
        // the GUILayout.Width call above the window will only ever be 100 pixels wide
        if (GUILayout.Button("Please click me a lot"))
        {
            print("Got a click");
        }
    }
}
```

## Window(int, Rect, WindowFunction, GUIContent, GUILayoutOption\[])

Make a popup window that layouts its contents automatically.

```csharp
public static Rect Window(int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique ID to use for each window. This is the ID you'll use to interface to it.**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the window. The layouting system will attempt to fit the window inside it - if that cannot be done, it will adjust the rectangle to fit.**** (\[WindowFunction]\(/engine/6000.6/script-reference/unityengine/gui/windowfunction)): The function that creates the GUI `inside` the window. This function must take one parameter - the `id` of the window it's currently making GUI for.**** (\[GUIContent]\(/engine/6000.6/script-reference/unityengine/guicontent)): Text, image and tooltip for this window.**** (\[GUILayoutOption\[]]\(/engine/6000.6/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style` or the `screenRect` you pass in.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.6/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.6/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.6/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.6/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.6/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.6/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.6/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.6/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                                                                               |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| [Rect](/engine/6000.6/script-reference/unityengine/rect.md) | The rectangle the window is at. This can be in a different position and have a different size than the one you passed in. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:

![GUILayoutWindow (Window)](/api/media?file=/engine/6000.6/media/images/GUILayoutWindow.png)

*Window in the Game View.*

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button will size to fit the window
        if (GUILayout.Button("Hello World"))
        {
            print("Got a click");
        }
    }
}
```

The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Here we instruct the layout system to
        // make the window 100 pixels wide no matter what.
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100));
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button is too large to fit the window
        // Normally, the window would have been expanded to fit the button, but due to
        // the GUILayout.Width call above the window will only ever be 100 pixels wide
        if (GUILayout.Button("Please click me a lot"))
        {
            print("Got a click");
        }
    }
}
```

## Window(int, Rect, WindowFunction, string, GUIStyle, GUILayoutOption\[])

Make a popup window that layouts its contents automatically.

```csharp
public static Rect Window(int id, Rect screenRect, GUI.WindowFunction func, string text, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique ID to use for each window. This is the ID you'll use to interface to it.**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the window. The layouting system will attempt to fit the window inside it - if that cannot be done, it will adjust the rectangle to fit.**** (\[WindowFunction]\(/engine/6000.6/script-reference/unityengine/gui/windowfunction)): The function that creates the GUI `inside` the window. This function must take one parameter - the `id` of the window it's currently making GUI for.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to display as a title for the window.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): An optional style to use for the window. If left out, the `window` style from the current [GUISkin](/engine/6000.6/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.6/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style` or the `screenRect` you pass in.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.6/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.6/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.6/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.6/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.6/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.6/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.6/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.6/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                                                                               |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| [Rect](/engine/6000.6/script-reference/unityengine/rect.md) | The rectangle the window is at. This can be in a different position and have a different size than the one you passed in. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:

![GUILayoutWindow (Window)](/api/media?file=/engine/6000.6/media/images/GUILayoutWindow.png)

*Window in the Game View.*

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button will size to fit the window
        if (GUILayout.Button("Hello World"))
        {
            print("Got a click");
        }
    }
}
```

The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Here we instruct the layout system to
        // make the window 100 pixels wide no matter what.
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100));
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button is too large to fit the window
        // Normally, the window would have been expanded to fit the button, but due to
        // the GUILayout.Width call above the window will only ever be 100 pixels wide
        if (GUILayout.Button("Please click me a lot"))
        {
            print("Got a click");
        }
    }
}
```

## Window(int, Rect, WindowFunction, Texture, GUIStyle, GUILayoutOption\[])

Make a popup window that layouts its contents automatically.

```csharp
public static Rect Window(int id, Rect screenRect, GUI.WindowFunction func, Texture image, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique ID to use for each window. This is the ID you'll use to interface to it.**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the window. The layouting system will attempt to fit the window inside it - if that cannot be done, it will adjust the rectangle to fit.**** (\[WindowFunction]\(/engine/6000.6/script-reference/unityengine/gui/windowfunction)): The function that creates the GUI `inside` the window. This function must take one parameter - the `id` of the window it's currently making GUI for.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display an image in the titlebar.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): An optional style to use for the window. If left out, the `window` style from the current [GUISkin](/engine/6000.6/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.6/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style` or the `screenRect` you pass in.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.6/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.6/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.6/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.6/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.6/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.6/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.6/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.6/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                                                                               |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| [Rect](/engine/6000.6/script-reference/unityengine/rect.md) | The rectangle the window is at. This can be in a different position and have a different size than the one you passed in. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:

![GUILayoutWindow (Window)](/api/media?file=/engine/6000.6/media/images/GUILayoutWindow.png)

*Window in the Game View.*

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button will size to fit the window
        if (GUILayout.Button("Hello World"))
        {
            print("Got a click");
        }
    }
}
```

The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Here we instruct the layout system to
        // make the window 100 pixels wide no matter what.
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100));
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button is too large to fit the window
        // Normally, the window would have been expanded to fit the button, but due to
        // the GUILayout.Width call above the window will only ever be 100 pixels wide
        if (GUILayout.Button("Please click me a lot"))
        {
            print("Got a click");
        }
    }
}
```

## Window(int, Rect, WindowFunction, GUIContent, GUIStyle, GUILayoutOption\[])

Make a popup window that layouts its contents automatically.

```csharp
public static Rect Window(int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique ID to use for each window. This is the ID you'll use to interface to it.**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the window. The layouting system will attempt to fit the window inside it - if that cannot be done, it will adjust the rectangle to fit.**** (\[WindowFunction]\(/engine/6000.6/script-reference/unityengine/gui/windowfunction)): The function that creates the GUI `inside` the window. This function must take one parameter - the `id` of the window it's currently making GUI for.**** (\[GUIContent]\(/engine/6000.6/script-reference/unityengine/guicontent)): Text, image and tooltip for this window.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): An optional style to use for the window. If left out, the `window` style from the current [GUISkin](/engine/6000.6/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.6/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style` or the `screenRect` you pass in.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.6/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.6/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.6/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.6/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.6/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.6/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.6/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.6/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                                                                               |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| [Rect](/engine/6000.6/script-reference/unityengine/rect.md) | The rectangle the window is at. This can be in a different position and have a different size than the one you passed in. |

### Remarks

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:

![GUILayoutWindow (Window)](/api/media?file=/engine/6000.6/media/images/GUILayoutWindow.png)

*Window in the Game View.*

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Notice the 3rd parameter
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button will size to fit the window
        if (GUILayout.Button("Hello World"))
        {
            print("Got a click");
        }
    }
}
```

The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    Rect windowRect = new Rect(20, 20, 120, 50);

    void OnGUI()
    {
        // Register the window. Here we instruct the layout system to
        // make the window 100 pixels wide no matter what.
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100));
    }

    // Make the contents of the window
    void DoMyWindow(int windowID)
    {
        // This button is too large to fit the window
        // Normally, the window would have been expanded to fit the button, but due to
        // the GUILayout.Width call above the window will only ever be 100 pixels wide
        if (GUILayout.Button("Please click me a lot"))
        {
            print("Got a click");
        }
    }
}
```
