Reputation: 23739
Code:
#!/usr/bin/perl -w
use strict;
use Curses::UI;
my $cui = new Curses::UI( -color_support => 1 );
my $win = $cui->add(
'win', 'Window',
-border => 1,
-y => 1,
-bfg => 'red',
);
my $listbox = $win->add(
'mylistbox', 'Listbox',
-values => [1, 2, 3],
-labels => { 1 => 'One',
2 => 'Two',
3 => 'Three' },
-radio => 1,
-height => 15,
);
my $buttons = $win->add(
'mybuttons', 'Buttonbox',
-buttons => [
{
-label => '< Ok >',
-value => 1,
-onpress => sub { die "Do not press this button!\n"; },
}
],
);
$listbox->focus();
$cui->mainloop();
Output after I run the program and click <tab>
:
As you see the button was put behind the listbox. How can I put the button below the listbox, centering it horizontally, like this:
And what are the methods to position the ncurses widgets horizontally and vertically in Perl, related to the other widgets?
Upvotes: 2
Views: 594
Reputation: 2494
use strict;
use Curses::UI;
my $cui = new Curses::UI( -color_support => 1 );
my $win = $cui->add(
'win', 'Window',
-border => 0,
-y => 1,
-bfg => 'red',
);
my $listbox = $win->add(
'mylistbox', 'Listbox',
-values => [1, 2, 3],
-labels => { 1 => 'One',
2 => 'Two',
3 => 'Three' },
-radio => 1,
-border =>1,
-height => 5,
);
my $buttons = $win->add(
'mybuttons', 'Buttonbox',
-buttons => [
{
-label => '< Ok >',
-value => 1,
-onpress => sub { die "Do not press this button!\n"; },
}
],
-y => ($win->height-$listbox->height)/2+$listbox->height,
-width =>8,
-border=>1,
-x=>$win->width/2-4
);
$listbox->focus();
$cui->set_binding( sub {exit 0;}, "q");
$cui->mainloop();
Upvotes: 1