NAME

Gtk2::Ex::ArrayMenu -- menu of items from an array

SYNOPSIS

use Gtk2::Ex::ArrayMenu;

my $menu = Gtk2::Ex::ArrayMenu->new (array => ['One', 'Two']);

# standalone popup
$menu->popup;

# or as a submenu
$item->set_submenu ($menu);

WIDGET HIERARCHY

Gtk2::Ex::ArrayMenu is a subclass of Gtk2::Menu.

Gtk2::Widget
  Gtk2::Container
    Gtk2::MenuShell
      Gtk2::Menu
        Gtk2::Ex::ArrayMenu

DESCRIPTION

A Gtk2::Ex::ArrayMenu presents menu items from a given array of values. Those values can be strings to show directly, or functions can be set to form the strings, and make other setups. A single activate signal on the ArrayMenu is called for any item activated.

A new array of desired items to show can be set at any time and the number of items and their contents are changed accordingly. The work in doing that is left until the menu is popped up.

FUNCTIONS

Gtk2::Ex::ArrayMenu->new (key=>value,...)

Create and return a new VAxis widget. Optional key/value pairs set initial properties, as per Glib::Object->new. Eg.

my $adj = Gtk2::Adjustment->new (5,0,20, 1,8, 10);
Gtk2::Ex::VAxis->new (adjustment => $adj,
                       decimals => 1);

SIGNALS

activate, parameters ($arraymenu, $elem, $userdata)

Emitted when the user activates one of the items within the arraymenu. The corresponding array element is passed as a parameter.

PROPERTIES

array (array reference, default empty [])

Array of items to display.

use-mnemonic (boolean, default true)

Whether to interpret underscores "_" in the item names as mnemonics.

name-proc (code reference, default undef)

Procedure to call to get the item name from an array element. The default undef means to expect the elements to be strings, or to stringize with "$elem" in the usual way. Setting a procedure allows some sub-field of an element to be used. name-proc is called as

$str = my_name_proc ($arraymenu, $elem);

So for instance

sub my_name_proc {
  my ($arraymenu, $elem) = @_;
  return $elem->{'name'};
}
$arraymenu->set ('name-proc', \&my_name_proc);

The default stringizing means that if the elements are objects then they can overload the stringizing operator "" (see overload). But unless you've want a stringize like that for other purposes it's far clearer to set a specific name-proc here.

SEE ALSO

Gtk2::Menu, Gtk2::MenuItem, Gtk2::Label