Extension: omni.kit.menu.utils-1.7.3 |
Documentation Generated: Nov 07, 2024 |
Overview
omni.kit.menu.utils allows users to add/remove/update menus for the top bar of the window.
Delegates
You can have a delegate associated with your menu
Currently supported functions are:
build_item(item: ui.Menu)
created ui for menu items, be careful overriding this function as IconMenuDelegate has a custom build_item
get_elided_length(menu_name: str)
returns max string length & any menu text over this length will be elided
get_menu_alignment() returns MenuAlignment.LEFT or MenuAlignment.RIGHT
used by “Live” and “Cache” button on top right. These are right aligned menu items with custom build_item function
update_menu_item(menu_item: Union[ui.Menu, ui.MenuItem], menu_refresh: bool)
allows modification of ui.Menu/ui.MenuItem.
menu_refresh
indicates its updating state during ui triggered_fn
Example
from omni.kit.menu.utils import MenuItemDescription, IconMenuDelegate
class FileMenuDelegate(IconMenuDelegate):
def build_item(item: ui.Menu):
super().build_item(item)
ui.Label("<<>>")
def get_menu_alignment(self):
return MenuAlignment.RIGHT
def update_menu_item(self, menu_item: Union[ui.Menu, ui.MenuItem], menu_refresh: bool):
if isinstance(menu_item, ui.MenuItem):
menu_item.visible = False
def get_elided_length(self, menu_name):
if menu_name == "Open Recent":
return 160
return 0
self._file_delegate = FileMenuDelegate()
self._file_menu_list = [
MenuItemDescription(
name="Menu Example",
glyph="file.svg",
onclick_action=("omni.kit.menuext.extension", "menu_example"),
hotkey=(carb.input.KEYBOARD_MODIFIER_FLAG_CONTROL, carb.input.KeyboardInput.T),
)]
omni.kit.menu.utils.add_menu_items(self._file_menu_list, "File", -10, delegate=self._file_delegate)