When working in UIT, use the below API to instantiate the container.
Controls that go inside a toolbar are named accordingly in UIT. (e.g. ToolbarButton)
When working in IMGUI, use the below API and use the style .Toolbar to instantiate the container. Most Editor controls have a toolbar-styled equivalent. Place controls inside the toolbar container using .Toolbar styling.
Window toolbar sits at the top of a window below the tab label and holds elements that affect or pertain to items in that window. These can include the layout of the window, the creation of objects or elements within the window, or a method of switching between windows and tabs in the same panel.
Using a toolbar when grouping multiple UI control elements improves access to important actions. Frequently used actions for windows or tabs should be added to the toolbar to help streamline the user’s access and enhance their workflow.
Placing elements on left and right edges
As all controls have a left and right border by default, use these left/right styles to remove the respective side border so they can be positioned to the far right or left of the toolbar without creating a double border. (eg. .ToolbarDropdownLeft .ToolbarDropdownRight)
Multiple toolbars
Primary toolbars should always be limited to universal elements. It is recommended to use only one toolbar where possible. However, a second toolbar can be used when there are relevant actions that relate to the window content.
Toolbar element groups
The window toolbar holds core control elements for key actions related to the window. Toolbar components can range from toggles for switching through different views to pop-ups for controlling what and how information is being displayed in the Editor.
Most Editor controls have a toolbar-styled equivalent. When working in IMGUI, place controls inside the toolbar container using .Toolbar styling.
Window toolbars should always be located near the edges of tabs or windows. They should be placed above and separate from other contents.
It is recommended to arrange toolbar elements to draw focus to high-traffic actions over low-traffic actions, with high-traffic actions to the left. Arranging content in this way is the most natural for human perception because users tend to scan the user interface from left to right starting from the upper left corner.
Toolbars can be arranged horizontally or vertically and should align along one axis to ease scanning by the user. Exceptions do exist where view controls are placed below tool groups, as in the tile palette window, but only in cases where the grouping is to centralize the elements in the window. This is to ensure readability and to minimize the real estate taken up by the toolbar.
Go to Window > UI Toolkit > Samples, to view code samples in C# / USS / UXML.
UI Toolkit
Unity - Scripting API:
Toolbar
IMGUI
Unity - Scripting API:
GUILayout.BeginHorizontal