# GetRect

> Reserve layout space for a rectangle for displaying some contents with a specific style.

## Definition

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

## GetRect(GUIContent, GUIStyle)

Reserve layout space for a rectangle for displaying some contents with a specific style.

```csharp
public static Rect GetRect(GUIContent content, GUIStyle style)
```

### Parameters

**** (\[GUIContent]\(/engine/6000.3/script-reference/unityengine/guicontent)): The content to make room for displaying.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): The [GUIStyle](/engine/6000.3/script-reference/unityengine/guistyle.md) to layout for.

### Returns

| Type                                                        | Description                                                                 |
| ----------------------------------------------------------- | --------------------------------------------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | A rectangle that is large enough to contain content when rendered in style. |

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Shows the button rect properties in a label when the mouse is over it
    GUIContent buttonText = new GUIContent("some button");
    GUIStyle buttonStyle = GUIStyle.none;

    void OnGUI()
    {
        Rect rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        if (rt.Contains(Event.current.mousePosition))
        {
            GUI.Label(new Rect(0, 20, 200, 70), "PosX: " + rt.x + "\nPosY: " + rt.y +
                "\nWidth: " + rt.width + "\nHeight: " + rt.height);
        }
        GUI.Button(rt, buttonText, buttonStyle);
    }
}
```

## GetRect(GUIContent, GUIStyle, GUILayoutOption\[])

Reserve layout space for a rectangle for displaying some contents with a specific style.

```csharp
public static Rect GetRect(GUIContent content, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[GUIContent]\(/engine/6000.3/script-reference/unityengine/guicontent)): The content to make room for displaying.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): The [GUIStyle](/engine/6000.3/script-reference/unityengine/guistyle.md) to layout for.**** (\[GUILayoutOption\[]]\(/engine/6000.3/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`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                                 |
| ----------------------------------------------------------- | --------------------------------------------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | A rectangle that is large enough to contain content when rendered in style. |

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Shows the button rect properties in a label when the mouse is over it
    GUIContent buttonText = new GUIContent("some button");
    GUIStyle buttonStyle = GUIStyle.none;

    void OnGUI()
    {
        Rect rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        if (rt.Contains(Event.current.mousePosition))
        {
            GUI.Label(new Rect(0, 20, 200, 70), "PosX: " + rt.x + "\nPosY: " + rt.y +
                "\nWidth: " + rt.width + "\nHeight: " + rt.height);
        }
        GUI.Button(rt, buttonText, buttonStyle);
    }
}
```

## GetRect(float, float)

Reserve layout space for a rectangle with a fixed content area.

```csharp
public static Rect GetRect(float width, float height)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The width of the area you want.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The height of the area you want.

### Returns

| Type                                                        | Description                           |
| ----------------------------------------------------------- | ------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | The rectangle to put your control in. |

## GetRect(float, float, GUIStyle)

Reserve layout space for a rectangle with a fixed content area.

```csharp
public static Rect GetRect(float width, float height, GUIStyle style)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The width of the area you want.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The height of the area you want.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): An optional [GUIStyle](/engine/6000.3/script-reference/unityengine/guistyle.md) to layout for. If specified, the style's `padding` value will be added to your sizes & its `margin` value will be used for spacing.

### Returns

| Type                                                        | Description                           |
| ----------------------------------------------------------- | ------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | The rectangle to put your control in. |

## GetRect(float, float, GUILayoutOption\[])

Reserve layout space for a rectangle with a fixed content area.

```csharp
public static Rect GetRect(float width, float height, params GUILayoutOption[] options)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The width of the area you want.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The height of the area you want.**** (\[GUILayoutOption\[]]\(/engine/6000.3/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`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                           |
| ----------------------------------------------------------- | ------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | The rectangle to put your control in. |

## GetRect(float, float, GUIStyle, GUILayoutOption\[])

Reserve layout space for a rectangle with a fixed content area.

```csharp
public static Rect GetRect(float width, float height, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The width of the area you want.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The height of the area you want.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): An optional [GUIStyle](/engine/6000.3/script-reference/unityengine/guistyle.md) to layout for. If specified, the style's `padding` value will be added to your sizes & its `margin` value will be used for spacing.**** (\[GUILayoutOption\[]]\(/engine/6000.3/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`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                           |
| ----------------------------------------------------------- | ------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | The rectangle to put your control in. |

## GetRect(float, float, float, float)

Reserve layout space for a flexible rect.

```csharp
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.

### Returns

| Type                                                        | Description                                                     |
| ----------------------------------------------------------- | --------------------------------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | A rectangle with size between minWidth & maxWidth on both axes. |

### Remarks

The rectangle's size will be between the min & max values.

## GetRect(float, float, float, float, GUIStyle)

Reserve layout space for a flexible rect.

```csharp
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): An optional style. If specified, the style's `padding` value will be added to the sizes requested & the style's `margin` values will be used for spacing.

### Returns

| Type                                                        | Description                                                     |
| ----------------------------------------------------------- | --------------------------------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | A rectangle with size between minWidth & maxWidth on both axes. |

### Remarks

The rectangle's size will be between the min & max values.

## GetRect(float, float, float, float, GUILayoutOption\[])

Reserve layout space for a flexible rect.

```csharp
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, params GUILayoutOption[] options)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.**** (\[GUILayoutOption\[]]\(/engine/6000.3/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`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                     |
| ----------------------------------------------------------- | --------------------------------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | A rectangle with size between minWidth & maxWidth on both axes. |

### Remarks

The rectangle's size will be between the min & max values.

## GetRect(float, float, float, float, GUIStyle, GUILayoutOption\[])

Reserve layout space for a flexible rect.

```csharp
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The minimum width of the area passed back.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The maximum width of the area passed back.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): An optional style. If specified, the style's `padding` value will be added to the sizes requested & the style's `margin` values will be used for spacing.**** (\[GUILayoutOption\[]]\(/engine/6000.3/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`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                        | Description                                                     |
| ----------------------------------------------------------- | --------------------------------------------------------------- |
| [Rect](/engine/6000.3/script-reference/unityengine/rect.md) | A rectangle with size between minWidth & maxWidth on both axes. |

### Remarks

The rectangle's size will be between the min & max values.
