Class MenuSection
A labeled section within a menu that groups related menu items.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class MenuSection : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
MenuSection is a container element designed to organize menu items into logical groups with optional section headings. This helps users understand the relationship between different menu items and improves menu scanability.
Each section can display a title at the top, followed by any number of menu items. Sections are commonly used in larger menus to create visual hierarchy and group related functionality.
Sections have picking mode set to ignore by default, making them non-interactive containers. The title is automatically hidden when not set or empty.
Tip: Combine MenuSection with MenuDivider to create clear visual separation between different functional areas of your menu.
Examples
Basic Menu Section: Organizing menu items into logical sections
<ui:Menu>
<ui:MenuSection title="Edit">
<ui:MenuItem label="Undo" icon="undo" shortcut="Ctrl+Z" />
<ui:MenuItem label="Redo" icon="redo" shortcut="Ctrl+Y" />
</ui:MenuSection>
<ui:MenuDivider />
<ui:MenuSection title="Clipboard">
<ui:MenuItem label="Cut" icon="scissors" shortcut="Ctrl+X" />
<ui:MenuItem label="Copy" icon="copy" shortcut="Ctrl+C" />
<ui:MenuItem label="Paste" icon="clipboard" shortcut="Ctrl+V" />
</ui:MenuSection>
</ui:Menu>
Section Without Title: Using sections for structure without always showing titles
<ui:Menu>
<ui:MenuSection>
<ui:MenuItem label="New Window" />
<ui:MenuItem label="New Tab" />
</ui:MenuSection>
<ui:MenuDivider />
<ui:MenuSection title="Tools">
<ui:MenuItem label="Settings" icon="settings" />
<ui:MenuItem label="Extensions" icon="puzzle" />
</ui:MenuSection>
</ui:Menu>
Creating Sections Programmatically: Building a structured menu with sections in code
var menu = new Menu();
// Create first section
var editSection = new MenuSection ;
editSection.Add(new MenuItem { label = "Undo", shortcut = "Ctrl+Z" });
editSection.Add(new MenuItem { label = "Redo", shortcut = "Ctrl+Y" });
menu.Add(editSection);
// Add separator
menu.Add(new MenuDivider());
// Create second section
var viewSection = new MenuSection ;
viewSection.Add(new MenuItem { label = "Zoom In", shortcut = "Ctrl++" });
viewSection.Add(new MenuItem { label = "Zoom Out", shortcut = "Ctrl+-" });
viewSection.Add(new MenuItem { label = "Full Screen", shortcut = "F11" });
menu.Add(viewSection);
Complex Menu Structure: Building a menu with dynamic content and multiple section types
var menu = new Menu();
// Recent files section
var recentSection = new MenuSection ;
for (int i = 0; i < 5; i++)
{
recentSection.Add(new MenuItem .txt",
icon = "file"
});
}
menu.Add(recentSection);
menu.Add(new MenuDivider());
// Settings section with toggles
var settingsSection = new MenuSection ;
settingsSection.Add(new MenuItem {
label = "Auto-Save",
selectable = true,
value = true
});
settingsSection.Add(new MenuItem {
label = "Show Tooltips",
selectable = true,
value = true
});
menu.Add(settingsSection);
Constructors
MenuSection()
Default constructor.
Declaration
public MenuSection()
Fields
containerUssClassName
The MenuSection container styling class.
Declaration
public const string containerUssClassName = "appui-menusection__container"
Field Value
| Type | Description |
|---|---|
| string |
titleUssClassName
The MenuSection title styling class.
Declaration
public const string titleUssClassName = "appui-menusection__title"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The MenuSection main styling class.
Declaration
public const string ussClassName = "appui-menusection"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The MenuSection container.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
title
The text to display in the section heading.
Declaration
[CreateProperty]
[UxmlAttribute]
public string title { get; set; }
Property Value
| Type | Description |
|---|---|
| string |