Class MenuBuilder
A utility class to build a Menu programmatically.
Inherited Members
Namespace: UnityEngine.Dt.App.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
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
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
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 |
|