Implementation references

Scripting API and implementation references.

UI Toolkit
IMGUI

Overview

1. Toolbar - regular search field 2. Toolbar - popup search field

Unity Editor contains four types of search fields:

  • A search field is an input field that allows users to enter a text string to be searched for
  • The search field enables a query of a database, program or search engine
  • The search function allows users to quickly locate desired information instead of manually exploring the platform to find information

Basic search field variations

Toolbar search field and toolbar popup search field in dark theme

Toolbar - regular search field

A basic slider
When to use

A toolbar search field is an input field in toolbars that allows users to enter text to be searched for.

Slider icon
UI Builder allows visual creation of UI assets in UI Toolkit, and is available as a built-in feature {2021.1 and later} or a package {2020.3 and earlier}
API in

UI Toolkit

ToolbarSearchField
A search field for the toolbar
API in

IMGUI

EditorGUI.ToolbarSearch
Field
A search field for the toolbar
Internal API
Use EditorGUILayout.ToolbarSearchField to set the position and scaling rules of the field automatically.
Toolbar - popup search field
A min max slider
When to use

A toolbar search field with a pop-up (dropdown menu) used for filtering search queries.

A min max slider icon
UI Builder allows visual creation of UI assets in UI Toolkit, and is available as a built-in feature {2021.1 and later} or a package {2020.3 and earlier}
API in

UI Toolkit

ToolbarPopupSearchField
A pop-up search field for the toolbar
API in

IMGUI

EditorGUI.ToolbarSearch
Field
Use + ToolbarSearchFieldwithJumpPopup  for rendering a pop-up search field with a dropdown menu
Internal API

IMGUI

Use EditorGUILayout.ToolbarSearchField to set the position and scaling rules of the field automatically.

Guidance

When to use

  • Use a Toolbar Search Field to enable users quickly locate an Asset or a Scene Object
  • If the search query of the database (Asset Library / Scene Objects) needs to be categorized by type, use a Toolbar Pop-up Search Field

When to use a condensed search field

  • Use a Condensed Search Field to simplify the UI when search is not the primary functionality in the area
  • The Condensed Search Field usually reduces discoverability of the search functionality compared to the regular search field: consider whether this reduced discoverability is worth the trade-off for a more simplified UI

Style

Search fields appear in toolbars and follow the same principles as other toolbar controls.

Length of field
A basic slider with a text label on the left and a numeric field on the right.
Search field in minimum width

Recommended minimum width:
To allow for legible user input, the recommended minimum width for search fields are 150 px, or 20 characters.

Condensed search field styling
A basic slider with a text label on the left and a numeric field on the right.
Condensed search field styled in a few different contexts

The Condensed Search Field in its collapsed state adapts its styling to the context in which it appears, matching the appearance of other icon buttons in the area.

Behavior

Search results
A basic slider with a text label on the left and a numeric field on the right.
Searching for a crate texture in Project library

Search results of a query is displayed immediately while a user is typing.

Search filters
A basic slider with a text label on the left and a numeric field on the right.
Hierarchy toolbar popup search field is displaying object type filters

Toolbar Pop-up Search Fields allows users to set object type filters for their search query with a dropdown menu.

Expand and collapse

In its collapsed state, the Condensed Search Field appears as an icon button with a search icon. Clicking on the search button expands the Condensed Search Field into a Regular Search Field and a collapse button, and automatically places focus on the Search Field.

Clicking on the collapse button collapses the Condensed Search Field back into its collapsed state. If the Search Field is empty, clicking outside of the Search Field removes focus from it and automatically collapses it. If there is input in the Search Field, clicking outside of the Search Field does not automatically collapse it.

Icon of a letter I in a blue circle indicating this is a piece of informational content
Covering or pushing surrounding UI
If space allows, the expansion of the Condensed Search Field should push surrounding UI away. If there is little space in the UI, the expanded Search Field may cover surrounding UI, as it is considered a transient state.

Formatting

Anatomy and layout

Anatomy
Anatomy of a toolbar search field and toolbar popup search field and its key parts

A search field can contain following elements:

1. Search / popup search icons
2. Clear icon
3. Body (container)
4. User input
5. Filter label (popup search fields)
6. Popup menu
7. Condensed search button
8. Collapse button

1. Search / Popup search icons

Pop-up search icon is used to open the dropdown menu.

2. Clear icon

Used to clear user input.

3. Body (container)

The body of the search field is the container where content (Icons, User input, Filter label) is displayed.

4. User input

The search query input by the user inside the search field.

5. Filter label

Label of the selected filter in pop up search fields.

6. Pop-up menu
7. Condensed search button

Condensed state of the Condensed Search Field appears as an icon button.

8. Collapse button

Collapse button used to collapse a Condensed Search Field from its expanded state.

Interaction states

Toolbar search field in its interactive states
Default

Default state of a Search Field.

Hover

When hovering over a search field body the border will be highlighted. Additionally, the user’s default cursor will switch to a Line Cursor glyph to indicate the nature of the element.

Focused

When a search field enters the Focused state its content will be highlighted in addition to its borders. This is because the content is being selected, allowing for the user to interact with it immediately (for example by immediately deleting or copying all of it).

Icon of a letter I in a blue circle indicating this is a piece of informational content
Placeholder text
For the Regular Search Field, placeholder text inside the Search Field disappears upon user focus.

For the Condensed Search Field, placeholder text inside the Search Field should stay in the field upon user focus, only disappearing upon user input. This enables the user to see the placeholder text even when the expansion of the Search Field automatically places focus on it.
Disabled

A search field that is disabled will indicate so by having its body “greyed out” and will not accept inputs or react to hovering.

Condensed search field in its collapsed and expanded states
Collapsed

A collapsed Condensed Search Field appears as a search icon button.

Expanded

A search field that is disabled will indicate so by having its body “greyed out” and will not accept inputs or react to hovering.

Color

1. icon 2. text 3. input_field-border 4. input_field-background
1. icon
Primary Icon Color
Icons that don’t require to be color coded uses this color
#555555
#C4C4C4
2. text
--unity-colors-button-border-pressed
The border color for a button control when it is pressed
#707070
#0D0D0D
3. input_field-border
--unity-colors-helpbox-text
The text color for a helpbox control
#161616
#BDBDBD
--unity-colors-highlight-background
The background color for selected items or selected text
#3A72B0
#2C5D87
--unity-colors-highlight-background-hover
The background color for line items when the mouse pointer hovers over them
rgba(0, 0, 0, 0.0627451)
rgba(256, 256, 256, 0.0627451)
--unity-colors-highlight-background-hover-lighter
The background color for an item with a line specific background color when the mouse pointer hovers over them
#9A9A9A
#5F5F5F
4. input_field-background
--unity-colors-helpbox-border
The border color for a helpbox control
#A9A9A9
#232323

Code samples

UI Toolkit samples

Icon indicating this element is available in UI Builder

Go to Window > UI Toolkit > Samples, to view code samples in C# / USS / UXML.

Slider icon

Code references

Scripting references for

IMGUI

IMGUI

Internal API
EditorGUI.ToolbarSearchField is not available as a public API class in IMGUI framework.