2

代码:

#!/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>

在此处输入图像描述

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

在此处输入图像描述

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

4

1 回答 1

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();
于 2013-10-16T19:20:33.090 回答