The Tkui\Widgets\Menu\Menu class is used to create menu bars and dropdown menus. You can add submenus, individual menu items, separators, or groups of items to a Menu instance.
Key Methods:
addMenu(string $title): Creates and returns a new Menu instance as a submenu (cascade) under the current menu. Supports underline characters for keyboard shortcuts.addItem(CommonItem $item): Adds a single menu item (like MenuItem) to the menu.addSeparator(): Adds a visual separator between items.addGroup(CommonGroup $group): Adds a collection of menu items at once.
When constructing a Menu, you can pass the following options:
postCommand: A callable executed when the menu is displayed.selectColor: A Color or string defining the selection color.title: The title of the menu.
use Tkui//...;
use Tkui//...;
$menu = new Menu($parent, [
'title' => 'File',
'selectColor' => 'blue',
]);
// Adding a submenu
$fileMenu = $menu->addMenu("File");
// Adding a single item
$fileMenu->addItem(new MenuItem('Open', function() {
// Handle open action
}));
// Adding a separator
$fileMenu->addSeparator();