docs.unity3d.com
    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>.anchor
    AnchorPopup<MenuBuilder>.SetPlacement(PopoverPlacement)
    AnchorPopup<MenuBuilder>.SetOffset(Int32)
    AnchorPopup<MenuBuilder>.SetCrossOffset(Int32)
    AnchorPopup<MenuBuilder>.SetContainerPadding(Int32)
    AnchorPopup<MenuBuilder>.SetShouldFlip(Boolean)
    AnchorPopup<MenuBuilder>.SetArrowVisible(Boolean)
    AnchorPopup<MenuBuilder>.SetAnchor(VisualElement)
    AnchorPopup<MenuBuilder>.SetOutsideClickDismiss(Boolean)
    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(Boolean)
    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.context
    Popup.Dismiss()
    Popup.Dismiss(DismissType)
    Popup.Show()
    Popup.OnViewKeyDown(KeyDownEvent)
    Popup.FindSuitableParent(VisualElement)
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.AppUI.UI
    Syntax
    public class MenuBuilder : AnchorPopup<MenuBuilder>

    Constructors

    MenuBuilder(VisualElement, ApplicationContext, VisualElement, VisualElement)

    Constructor.

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

    The parent view of the Menu.

    ApplicationContext context

    The application context.

    VisualElement view

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

    VisualElement contentView

    The Menu's content visual element.

    Properties

    currentMenu

    The last menu in the stack.

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

    Methods

    AddAction(Int32, 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
    Int32 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.

    UnityEngine.UIElements.EventCallback<ClickEvent> callback

    The callback to invoke when the menu item is clicked.

    Returns
    Type Description
    MenuBuilder

    The MenuBuilder instance.

    AddAction(Int32, 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
    Int32 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.

    UnityEngine.UIElements.EventCallback<ClickEvent> callback

    The callback to invoke when the menu item is clicked.

    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
    Unity.AppUI.UI.AnchorPopup<Unity.AppUI.UI.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
    Unity.AppUI.UI.AnchorPopup<Unity.AppUI.UI.MenuBuilder>.InvokeDismissedEventHandlers(Unity.AppUI.Core.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(Int32, 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
    Int32 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.

    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
    Boolean

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

    Overrides
    Popup.ShouldAnimate()
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023