# OnGUI

> This function displays a search text field with the given Rect and UI style parameters.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.IMGUI.Controls](/engine/6000.5/script-reference/unityeditor/imgui/controls.md)
* **Assembly:** UnityEditor.CoreModule

## OnGUI(Rect, string, GUIStyle, GUIStyle, GUIStyle)

This function displays a search text field with the given Rect and UI style parameters.

```csharp
public string OnGUI(Rect rect, string text, GUIStyle style, GUIStyle cancelButtonStyle, GUIStyle emptyCancelButtonStyle)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle to use for the search field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text string to display in the search field.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): The text field style.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): The cancel button style used when there is text in the search field.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): The cancel button style used when there is no text in the search field.

### Returns

| Type                                                           | Description                                                                                                                  |
| -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The text entered in the SearchField. The original input string is returned instead if the search field text was not changed. |

### Remarks

Use this function to customize the UI style of the search text field. You must set cancelButtonStyle.fixedWidth to a suitable and desired width as this affects the placement of the close button to the right of the search text field.

## OnGUI(Rect, string)

This function displays the search field with the default UI style in the given Rect.

```csharp
public string OnGUI(Rect rect, string text)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle to use for the search field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text string to display in the search field.

### Returns

| Type                                                           | Description                                                                                                                   |
| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The text entered in the search field. The original input string is returned instead if the search field text was not changed. |

## OnGUI(string, GUILayoutOption\[])

This function displays the search field with the default UI style and uses the GUILayout class to automatically calculate the position and size of the Rect it is rendered to. Pass an optional list to specify extra layout properties.

```csharp
public string OnGUI(string text, params GUILayoutOption[] options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text string to display in the search field.**** (\[GUILayoutOption\[]]\(/engine/6000.5/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layout properties. \
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.5/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.5/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.5/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.5/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.5/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.5/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.5/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.5/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                           | Description                                                                                                                   |
| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The text entered in the search field. The original input string is returned instead if the search field text was not changed. |
