# MainToolbarCustomElement

> Describes a main toolbar element that wraps an arbitrary `VisualElement`.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.Toolbars](/engine/6000.7/script-reference/unityeditor/toolbars.md)
* **Assembly:** UnityEditor
* **Inherits from:** [MainToolbarElement](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarelement.md)

```csharp
[Icon("UIToolkit/Icons/CustomCSharpElement.png")]
public sealed class MainToolbarCustomElement : MainToolbarElement
```

## Remarks

Use this class to add a main toolbar element whose content doesn't match any of the other [MainToolbarElement](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarelement.md) types, such as [MainToolbarButton](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarbutton.md) or [MainToolbarToggle](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbartoggle.md). To add a custom element to the main toolbar use a static method registered with [MainToolbarElementAttribute](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarelementattribute.md) to return this class.

## Examples

```csharp
using UnityEditor;
using UnityEditor.Toolbars;
using UnityEngine.UIElements;

public class MainToolbarCustomElementExample
{
    [MainToolbarElement("Examples/Custom Clock", defaultDockPosition = MainToolbarDockPosition.Middle)]
    public static MainToolbarElement ClockElement()
    {
        return new MainToolbarCustomElement(() =>
        {
            var label = new Label();
            label.schedule.Execute(() => label.text = System.DateTime.Now.ToLongTimeString()).Every(1000);
            return label;
        });
    }
}
```

## Constructors

| Constructor                                                                                                                                                           | Description                                                           |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [MainToolbarCustomElement(System.Func\{UnityEngine.UIElements.VisualElement})](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarcustomelement/ctor.md) | Specify the `VisualElement` content of a main toolbar custom element. |

## Inheritance

**Inherited Members:**

* [MainToolbarElement.content](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarelement/content.md)
* [MainToolbarElement.displayed](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarelement/displayed.md)
* [MainToolbarElement.enabled](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarelement/enabled.md)
* [MainToolbarElement.populateContextMenu](/engine/6000.7/script-reference/unityeditor/toolbars/maintoolbarelement/populatecontextmenu.md)
