Question

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>:

enter image description here

As you see the button was put behind the listbox. How can I put the button below the listbox, centering it horizontally, like this:

enter image description here

And what are the methods to position the ncurses widgets horizontally and vertically in Perl, related to the other widgets?

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top