如何在Perl中定位ncurses小部件

时间:2013-10-15 14:13:23

标签: perl ncurses

代码:

#!/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();

运行程序后输出并单击<tab>

enter image description here

如您所见,按钮被放在列表框后面。如何将按钮放在列表框下方,将其水平居中,如下所示:

enter image description here

在Perl中水平和垂直定位ncurses小部件的方法有哪些,与其他小部件相关?

1 个答案:

答案 0 :(得分:1)

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();