docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MenuBuilder

    A utility class to build a Menu programmatically.

    Inheritance
    object
    Popup
    Popup<MenuBuilder>
    AnchorPopup<MenuBuilder>
    MenuBuilder
    Inherited Members
    AnchorPopup<MenuBuilder>.placement
    AnchorPopup<MenuBuilder>.currentPlacement
    AnchorPopup<MenuBuilder>.offset
    AnchorPopup<MenuBuilder>.crossOffset
    AnchorPopup<MenuBuilder>.containerPadding
    AnchorPopup<MenuBuilder>.shouldFlip
    AnchorPopup<MenuBuilder>.arrowVisible
    AnchorPopup<MenuBuilder>.outsideClickDismissEnabled
    AnchorPopup<MenuBuilder>.outsideScrollEnabled
    AnchorPopup<MenuBuilder>.outsideClickStrategy
    AnchorPopup<MenuBuilder>.anchor
    AnchorPopup<MenuBuilder>.SetPlacement(PopoverPlacement)
    AnchorPopup<MenuBuilder>.SetOffset(int)
    AnchorPopup<MenuBuilder>.SetCrossOffset(int)
    AnchorPopup<MenuBuilder>.SetContainerPadding(int)
    AnchorPopup<MenuBuilder>.SetShouldFlip(bool)
    AnchorPopup<MenuBuilder>.SetArrowVisible(bool)
    AnchorPopup<MenuBuilder>.SetAnchor(VisualElement)
    AnchorPopup<MenuBuilder>.SetOutsideClickDismiss(bool)
    AnchorPopup<MenuBuilder>.SetOutsideScrollEnabled(bool)
    AnchorPopup<MenuBuilder>.SetOutsideClickStrategy(OutsideClickStrategy)
    AnchorPopup<MenuBuilder>.ShowView()
    AnchorPopup<MenuBuilder>.AnimateViewIn()
    AnchorPopup<MenuBuilder>.ShouldDismiss(DismissType)
    AnchorPopup<MenuBuilder>.HideView(DismissType)
    AnchorPopup<MenuBuilder>.AnimateViewOut(DismissType)
    AnchorPopup<MenuBuilder>.RefreshPosition()
    Popup<MenuBuilder>.m_LastFocusedElement
    Popup<MenuBuilder>.shown
    Popup<MenuBuilder>.dismissed
    Popup<MenuBuilder>.SetKeyboardDismiss(bool)
    Popup<MenuBuilder>.SetLastFocusedElement(Focusable)
    Popup<MenuBuilder>.InvokeShownEventHandlers()
    Popup.k_NextFrameDurationMs
    Popup.k_PopupShow
    Popup.k_PopupDismiss
    Popup.handler
    Popup.keyboardDismissEnabled
    Popup.view
    Popup.targetParent
    Popup.contentView
    Popup.Dismiss()
    Popup.Dismiss(DismissType)
    Popup.Show()
    Popup.OnViewKeyDown(KeyDownEvent)
    Popup.FindSuitableParent(VisualElement)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.AppUI.UI
    Assembly: Unity.AppUI.dll
    Syntax
    public class MenuBuilder : AnchorPopup<MenuBuilder>

    Constructors

    MenuBuilder(VisualElement, VisualElement, VisualElement)

    Constructor.

    Declaration
    public MenuBuilder(VisualElement parentView, VisualElement view, VisualElement contentView)
    Parameters
    Type Name Description
    VisualElement parentView

    The parent view of the Menu.

    VisualElement view

    The Menu visual element (used by the popup system).

    VisualElement contentView

    The Menu's content visual element.

    Properties

    closeOnSelection

    Close the menu automatically when an item is selected.

    Declaration
    public bool closeOnSelection { get; }
    Property Value
    Type Description
    bool

    currentMenu

    The last menu in the stack.

    Declaration
    public Menu currentMenu { get; }
    Property Value
    Type Description
    Menu

    Methods

    AddAction(int, Action<MenuItem>)

    Add an Action menu item to the current menu.

    Declaration
    public MenuBuilder AddAction(int actionId, Action<MenuItem> bindItemFunc)
    Parameters
    Type Name Description
    int actionId

    A unique identifier for the action.

    Action<MenuItem> bindItemFunc

    A callback to bind the action.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    AddAction(int, string, string, string, EventCallback<ClickEvent>)

    Add an Action menu item to the current menu.

    Declaration
    public MenuBuilder AddAction(int actionId, string labelStr, string iconName, string shortcut, EventCallback<ClickEvent> callback)
    Parameters
    Type Name Description
    int actionId

    A unique identifier for the action.

    string labelStr

    The raw label of the menu item (will be localized).

    string iconName

    The icon of the menu item.

    string shortcut

    The shortcut of the menu item.

    EventCallback<ClickEvent> callback

    The callback to invoke when the menu item is clicked.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    AddAction(int, string, string, EventCallback<ClickEvent>)

    Add an Action menu item to the current menu.

    Declaration
    public MenuBuilder AddAction(int actionId, string labelStr, string iconName, EventCallback<ClickEvent> callback)
    Parameters
    Type Name Description
    int actionId

    A unique identifier for the action.

    string labelStr

    The raw label of the menu item (will be localized).

    string iconName

    The icon of the menu item.

    EventCallback<ClickEvent> callback

    The callback to invoke when the menu item is clicked.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    AddDivider(Action<MenuDivider>)

    Add a Menu Divider to the current menu.

    Declaration
    public MenuBuilder AddDivider(Action<MenuDivider> bindDividerFunc = null)
    Parameters
    Type Name Description
    Action<MenuDivider> bindDividerFunc

    A callback to bind the divider.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    AddSection(Action<MenuSection>)

    Add a Section to the current menu.

    Declaration
    public MenuBuilder AddSection(Action<MenuSection> bindSectionFunc = null)
    Parameters
    Type Name Description
    Action<MenuSection> bindSectionFunc

    A callback to bind the section.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    Build(VisualElement, Menu)

    Create a MenuBuilder instance.

    Declaration
    public static MenuBuilder Build(VisualElement referenceView, Menu menu = null)
    Parameters
    Type Name Description
    VisualElement referenceView

    The reference view to position the menu.

    Menu menu

    The menu to display.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    GetFocusableElement()

    Returns the element that will be focused when the view will become visible.

    The default value is `null`.

    Declaration
    protected override VisualElement GetFocusableElement()
    Returns
    Type Description
    VisualElement

    The element that will be focused when the view will become visible.

    Overrides
    Popup.GetFocusableElement()

    GetMovableElement()

    Method which must return the visual element that needs to be moved, based on the anchor position and size.

    Declaration
    protected override VisualElement GetMovableElement()
    Returns
    Type Description
    VisualElement

    The visual element which will be moved. The default value is view.

    Overrides
    AnchorPopup<MenuBuilder>.GetMovableElement()

    InvokeDismissedEventHandlers(DismissType)

    Called when the popup has been dismissed. This method will invoke any handlers attached to the dismissed event.

    Declaration
    protected override void InvokeDismissedEventHandlers(DismissType reason)
    Parameters
    Type Name Description
    DismissType reason
    Overrides
    AnchorPopup<MenuBuilder>.InvokeDismissedEventHandlers(DismissType)

    Pop()

    Go back to the parent menu and make it the current menu.

    Declaration
    public MenuBuilder Pop()
    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    PushSubMenu(Action<MenuItem>)

    Create an action menu item, add a sub-menu to the current menu, and make it the current menu.

    Declaration
    public MenuBuilder PushSubMenu(Action<MenuItem> bindItemFunc)
    Parameters
    Type Name Description
    Action<MenuItem> bindItemFunc

    A callback to bind the action.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    Remarks

    When the binding callback is invoked, the sub-menu is already pushed on the stack and set on the menu item.

    PushSubMenu(int, string, string)

    Create an action menu item, add a sub-menu to the current menu, and make it the current menu.

    Declaration
    public MenuBuilder PushSubMenu(int actionId, string labelStr, string iconName)
    Parameters
    Type Name Description
    int actionId

    A unique identifier for the action.

    string labelStr

    The label of the menu item.

    string iconName

    The icon of the menu item.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    PushSubMenu(int, string, string, Action)

    Create an action menu item, add a sub-menu to the current menu, and make it the current menu.

    Declaration
    public MenuBuilder PushSubMenu(int actionId, string labelStr, string iconName, Action subMenuOpenedCallback)
    Parameters
    Type Name Description
    int actionId

    A unique identifier for the action.

    string labelStr

    The label of the menu item.

    string iconName

    The icon of the menu item.

    Action subMenuOpenedCallback

    The callback to invoke when the sub-menu is opened.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    SetCloseOnSelection(bool)

    Close the menu automatically when an item is selected.

    Declaration
    public MenuBuilder SetCloseOnSelection(bool value)
    Parameters
    Type Name Description
    bool value

    True to close the menu automatically when an item is selected.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    ShouldAnimate()

    Implement this method to know if the popup should call AnimateViewIn() and AnimateViewOut(DismissType) methods or not.

    Declaration
    protected override bool ShouldAnimate()
    Returns
    Type Description
    bool

    True if you want to animate the popup, False otherwise.

    Overrides
    Popup.ShouldAnimate()
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)