Curses::UI::Buttonbox3pm
Create and manipulate button widgets
Usage
use Curses::UI;my $cui = new Curses::UI;my $win = $cui->add('window_id', 'Window');my $buttons = $win->add('mybuttons', 'Buttonbox',-buttons => [{-label => '< Button 1 >',-value => 1,-shortcut => 1},{-label => '< Button 2 >',-value => 2,-shortcut => 2}]);$buttons->focus();my $value = $buttons->get();
Class hierarchy
Curses::UI::Widget|+----Curses::UI::Buttonbox
Overview
Curses::UI::Buttonbox is a widget that can be used to create an array of buttons (or, of course, only one button).
Options
-parent, -x, -y, -width, -height, -pad, -padleft, -padright, -padtop, -padbottom, -ipad, -ipadleft, -ipadright, -ipadtop, -ipadbottom, -title, -titlefullwidth, -titlereverse, -onfocus, -onblur
For an explanation of these standard options, see Curses::UI::Widget.
Options
- •
-
-buttons< ARRAYREF >This option takes a reference to a list of buttons. The list may contain both predefined button types and complete button definitions of your own.
* Your own button definition
A button definition is a reference to a hash. Thishash can have the following key-value pairs:obligatory:------------label This determines what text should be drawnon the button.optional:----------value This determines the returnvalue for theget() method. If the value is not defined,the get() method will return the indexof the button.-shortcut The button will act as if it was pressedif the key defined by -shortcut is pressed-onpress If the value for -onpress is a CODE reference,this code will be executes if the buttonis pressed, before the buttons widget losesfocus and returns.* Predefined button type
This module has a predefined list of frequently used buttontypes. Using these in B<-buttons> makes things a loteasier. The predefined button types are:ok -label => '< OK >'-shortcut => 'o'-value => 1-onpress => undefcancel -label => '< Cancel >'-shortcut => 'c'-value => 0-onpress => undefyes -label => '< Yes >'-shortcut => 'y'-value => 1-onpress => undefno -label => '< No >'-shortcut => 'n'-value => 0-onpress => undefExample:
....-buttons => [{ -label => '< My own button >',-value => 'mine!',-shortcut => 'm' },'ok','cancel',{ -label => '< My second button >',-value => 'another one',-shortcut => 's',-onpress => sub { die "Do not press this button!\n" } }]....
- •
-
-selected< INDEX >By default the first button (index = 0) is active. If you want another button to be active at creation time, add this option. The INDEX is the index of the button you want to make active.
- •
-
-buttonalignment< VALUE >You can specify how the buttons should be aligned in the widget. Available values for VALUE are 'left', 'middle' and 'right'.
- •
-
-vertical< BOOLEAN >When set to a true value, it will cause the buttons to be rendered with vertical instead of horizontal alignment.
Methods
- •
-
new( OPTIONS )
- •
-
layout( )
- •
-
draw( BOOLEAN )
- •
-
focus( )
- •
-
onFocus( CODEREF )
- •
-
onBlur( CODEREF )
- •
-
draw_if_visible( )These are standard methods. See Curses::UI::Widget for an explanation of these.
- •
-
get( )This method will return the index of the currently active button. If a value is given for that index (using the
-valueoption, see-buttonsabove), that value will be returned.
Default bindings
- •
-
<
enter>, <space>TODO: Fix dox Call the 'loose-focus' routine. By default this routine will have the container in which the widget is loose its focus. If you do not like this behaviour, then you can have it loose focus itself by calling:
$buttonswidget->set_routine('loose-focus', 'RETURN');For an explanation of
set_routine, see Curses::UI::Widget.
- •
-
<cursor left>, <
h>Call the 'previous' routine. This will make the previous button the active button. If the active button already is the first button, nothing will be done.
- •
-
<cursor right>, <
lCall the 'next' routine. This will make the next button the active button. If the next button already is the last button, nothing will be done.
- •
-
<any other key>
This will call the 'shortcut' routine. This routine will handle the shortcuts that are set by the
-shortcutsoption.
Releases
12 releases since Debian 3.1 (Sarge); the text changed 6 times.