AMenu#
Popup (context) menu.
| Header: | #include <AUI/Action/AMenu.h> |
| CMake: | aui_link(my_target PUBLIC aui::views) |
Detailed Description#
A menu is described with a model - a vector of AMenuItem structures with a name, an optional shortcut hint,
and an onAction handler.
The most common way to show a menu is to override AView::composeContextMenu; it is called when the user right
clicks the view (or long presses it on touchscreens). Return an empty model to show nothing.
class MyView : public AView {
protected:
AMenuModel composeContextMenu() override {
return {
{ .name = "Copy", .shortcut = AInput::CMD_CTRL + AInput::C, .onAction = [this] { copy(); } },
{ .type = AMenu::SEPARATOR },
{ .name = "Disabled", .enabled = false },
};
}
};
To show a menu on your own, call AMenu::show(model). Menus are closed with AMenu::close(); AMenu::isOpen()
tells whether there's an open menu.
Note
shortcut is a text hint only; AUI does not register it as a global hotkey. Handle the keys yourself, see
Handling input events.
Public Types#
Type#
enum AMenu::Type
| Constant | Description |
|---|---|
Type::SINGLE
|
|
Type::SUBLIST
|
|
Type::SEPARATOR
|