Menu - Garland-g/perl6-libui GitHub Wiki

Menu

Libui::Menu

Creates a menubar. Must be fully finished creating the menu before creating the App.

Order is important. To create a single Menu e.g. "File", create a Libui::Menu with the name "File". Each new Menu created will be added to the right of the most recently created menu.

Almost all of the Menu methods return MenuItems.

Example:

    Libui::Init();
    my Libui::Menu $file .= new("File");
    my Libui::MenuItem $open = $file.append-item("Open");
    my Libui::MenuItem $save = $file.append-item("Save");
    my Libui::MenuItem $quit = $file.append-quit-item;

    my Libui::Menu $edit .= new("Edit");
    my Libui::MenuItem $preferences = $edit.append-preferences-item;

    my Libui::Menu $help .= new("Help");
    my Libui::MenuItem $help-item = $help.append-item("Help");
    my Libui::MenuItem $about = $help.append-about-item;

    my Libui::App $app .= new("Application");
    ...

This will create:

  • "File" menu with "Open", "Save", and "Quit" items

  • "Edit" menu with a "Preferences" item

  • "Help" menu with a "Help" item and an "About" item

Laid out in the menubar like this:

File Edit Help

Libui will move the "About", "Quit", and "Preferences" items to their proper spots on MacOS automatically.

Methods

new(Str $name)

Creates a new Menu.

append-item(Str:D $name) returns Libui::MenuItem

Appends a new Menuitem to the Menu and returns it.

append-check-item(Str:D $name) returns Libui::MenuItem

Appends a new Checkable MenuItem to the Menu and returns it.

append-quit-item() returns Libui::MenuItem

Appends a MenuItem with the name "Quit" to the Menu and returns it.

append-preferences-item() returns Libui::MenuItem

Appends a MenuItem with the name "Preferences" to the Menu and returns it.

append-about-item() returns Libui::MenuItem

Appends a MenuItem with the name "About" to the Menu and returns it.

append-separator()

Appends a horizontal separator to the Menu.