Create and manipulate menubar widgets
Curses::UI::Widget | +----Curses::UI::Container | +----Curses::UI::Window | +----Curses::UI::Menubar
use Curses::UI; my $cui = new Curses::UI;
# define the menu datastructure. my $menu_data = [....];
my $menu = $cui->add( 'menu', 'Menubar', -menu => $menu_data );
$menu->focus();
This class can be used to add a menubar to Curses::UI. This menubar can contain a complete submenu hierarchy. It looks (remotely :-) like this:
------------------------------------- menu1 | menu2 | menu3 | .... ------------------------------------- +-------------+ |menuitem 1 | |menuitem 2 |+--------------+ |menuitem 3 >>||submenuitem 1 | |menuitem 4 ||submenuitem 2 | +-------------+|submenuitem 3 | |submenuitem 4 | |submenuitem 5 | +--------------+
See exampes/demo-Curses::UI::Menubar in the distribution for a short demo.
This class does not use any of the standard options that are provided by Curses::UI::Widget.
There is only one option: -menu. The value for this option is an \s-1ARRAYREF\s0. This \s-1ARRAYREF\s0 behaves exactly like the one that is described in Curses::UI::MenuListbox. The difference is that for the top-level menu, you will only use -submenu's. Example data structure:
my $menu1 = [ { -label => 'option 1', -value => '1-1' }, { -label => 'option 2', -value => '1-2' }, { -label => 'option 3', -value => '1-3' }, ];
my $menu2 = [ { -label => 'option 1', -value => \&sel1 }, { -label => 'option 2', -value => \&sel2 }, { -label => 'option 3', -value => \&sel3 }, ];
my $submenu = [ { -label => 'suboption 1', -value => '3-3-1' }, { -label => 'suboption 2', -callback=> \&do_it }, ];
my $menu3 = [ { -label => 'option 1', -value => \&sel2 }, { -label => 'option 2', -value => \&sel3 }, { -label => 'submenu 1', -submenu => $submenu }, ];
my $menu = [ { -label => 'menu 1', -submenu => $menu1 }, { -label => 'menu 2', -submenu => $menu2 } { -label => 'menu 3', -submenu => $menu3 } ];
new ( \s-1OPTIONS\s0 )
layout ( )
draw ( \s-1BOOLEAN\s0 )
focus ( ) These are standard methods. See Curses::UI::Widget for an explanation of these.
<escape> Call the 'escape' routine. This will have the menubar loose its focus and return the value '\s-1ESCAPE\s0' to the calling routine.
<tab> Call the 'return' routine. This will have the menubar loose its focus and return the value '\s-1LOOSE_FOCUS\s0' to the calling routine.
<cursor-down>, <j>, <enter> Call the 'pulldown' routine. This will open the menulistbox for the current menu and give that menulistbox the focus. What happens after the menulistbox loses its focus, depends upon the returnvalue of it: * the value '\s-1CURSOR_LEFT\s0' Call the 'cursor-left' routine and after that call the 'pulldown' routine. So this will open the menulistbox for the previous menu. * the value '\s-1CURSOR_RIGHT\s0' Call the 'cursor-right' routine and after that call the 'pulldown' routine. So this will open the menulistbox for the next menu. * the value '\s-1LOOSE_FOCUS\s0' The menubar will keep the focus, but no menulistbox will be open. * the value '\s-1ESCAPE\s0' The menubar will loose its focus and return the value 'ESCAPE' to the calling routine. * A \s-1CODE\s0 reference The code will be excuted, the menubar will loose its focus and the returnvalue of the CODE will be returned to the calling routine. * Any other value The menubar will loose its focus and the value will be returned to the calling routine.
<cursor-left>, <h> Call the 'cursor-left' routine. This will select the previous menu. If the first menu is already selected, the last menu will be selected.
<cursor-right>, <l> Call the 'cursor-right' routine. This will select the next menu. If the last menu is already selected, the first menu will be selected.
Curses::UI, Curses::UI::MenuListbox, Curses::UI::Listbox
Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
Maintained by Marcus Thiesen ([email protected])
This package is free software and is provided \*(L"as is\*(R" without express or implied warranty. It may be used, redistributed and/or modified under the same terms as perl itself.